ZQuest Classic Coverage Report


Directory: src/
File: src/zc/maps.cpp
Date: 2025-09-09 16:28:02
Exec Total Coverage
Lines: 4177 5229 79.9%
Functions: 293 332 88.3%
Branches: 3227 5326 60.6%

Line Branch Exec Source
1 #include "base/combo.h"
2 #include "base/handles.h"
3 #include "base/util.h"
4 #include "base/zdefs.h"
5 #include "base/general.h"
6 #include <cstring>
7 #include <assert.h>
8 #include <math.h>
9 #include <vector>
10 #include <deque>
11 #include <string>
12 #include <set>
13 #include <array>
14 #include <sstream>
15 using std::set;
16
17 #include "base/qrs.h"
18 #include "base/dmap.h"
19 #include "base/mapscr.h"
20 #include "base/misctypes.h"
21 #include "base/initdata.h"
22 #include "zc/maps.h"
23 #include "zc/zelda.h"
24 #include "zc/zc_ffc.h"
25 #include "tiles.h"
26 #include "sprite.h"
27 #include "gui/jwin.h"
28 #include "base/zsys.h"
29 #include "subscr.h"
30 #include "zc/zc_subscr.h"
31 #include "zc/hero.h"
32 #include "zc/guys.h"
33 #include "zc/ffscript.h"
34 #include "drawing.h"
35 #include "zc/combos.h"
36 #include "zc/replay.h"
37 #include "slopes.h"
38 #include "particles.h"
39 #include <fmt/format.h>
40 #include "zc/render.h"
41 #include "iter.h"
42 #include <ranges>
43
44 // All the temporary screens (and their layers) for the currently loaded map.
45 static mapscr* temporary_screens[136*7];
46 // Set by load_region.
47 static bool screen_in_current_region[136];
48 417 static rpos_handle_t current_region_rpos_handles[136*7];
49 static bool current_region_rpos_handles_dirty;
50 static int current_region_screen_count;
51 static std::pair<const rpos_handle_t*, int> current_region_rpos_handles_scr[136];
52
53 viewport_t viewport;
54 static int viewport_sprite_uid;
55 ViewportMode viewport_mode;
56 int world_w, world_h;
57 int region_scr_dx, region_scr_dy;
58 int region_scr_count;
59 rpos_t region_max_rpos;
60 int region_num_rpos;
61 region_t cur_region, scrolling_region;
62
63 417 maze_state_t maze_state;
64 int scrolling_maze_last_solved_screen;
65
66 577 void maps_init_game_vars()
67 {
68 577 viewport = {};
69 577 viewport_mode = ViewportMode::CenterAndBound;
70 577 viewport_sprite_uid = 1;
71 577 currscr_for_passive_subscr = -1;
72 577 }
73
74 static region_ids_t current_region_ids;
75
76 // Returns true if the (map, screen) is inside a scrolling region.
77 14621526 static bool is_in_scrolling_region(int map, int screen)
78 {
79 14621526 return get_region_id(map, screen) != 0;
80 }
81
82 bool is_in_screenscrolling_region(int screen)
83 {
84 if (!screenscrolling) return false;
85
86 int x = screen % 16;
87 int y = screen / 16;
88 return
89 scrolling_region.origin_screen_x >= x && scrolling_region.origin_screen_x < x + scrolling_region.screen_width &&
90 scrolling_region.origin_screen_y >= y && scrolling_region.origin_screen_y < y + scrolling_region.screen_height;
91 }
92
93 8240525708 bool is_in_scrolling_region()
94 {
95 8240525708 return cur_region.screen_count > 1;
96 }
97
98 2232 static bool is_same_region_id(int region_origin_scr, int map, int scr)
99 {
100
2/2
✓ Branch 0 taken 772 times.
✓ Branch 1 taken 1460 times.
2232 if (!is_in_scrolling_region(map, scr)) return false;
101 1460 int region_id = get_region_id(map, region_origin_scr);
102
1/2
✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
1460 return region_id && region_id == get_region_id(map, scr);
103 2232 }
104
105 138112532 bool is_in_current_region(int map, int screen)
106 {
107
2/2
✓ Branch 0 taken 1573 times.
✓ Branch 1 taken 138110959 times.
138112532 if (map != cur_map)
108 1573 return false;
109
110
3/4
✓ Branch 0 taken 138110959 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 138098746 times.
✓ Branch 3 taken 12213 times.
138110959 if (screen >= 0 && screen < 128)
111 138098746 return screen_in_current_region[screen];
112
113 12213 return screen == cur_screen;
114 138112532 }
115
116 211053909 bool is_in_current_region(int screen)
117 {
118
5/6
✓ Branch 0 taken 209938407 times.
✓ Branch 1 taken 1115502 times.
✓ Branch 2 taken 1115502 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 1115497 times.
211053909 return screen == cur_screen || (screen >= 0 && screen < 128 && screen_in_current_region[screen]);
119 }
120
121 29499450 bool is_in_current_region(mapscr* scr)
122 {
123
2/2
✓ Branch 0 taken 14690 times.
✓ Branch 1 taken 29484760 times.
29499450 return scr->map == cur_map && is_in_current_region(scr->screen);
124 }
125
126 76856734 bool is_extended_height_mode()
127 {
128
2/2
✓ Branch 0 taken 76606600 times.
✓ Branch 1 taken 250134 times.
76856734 return cur_region.screen_height > 1 && (DMaps[cur_dmap].flags & dmfEXTENDEDVIEWPORT);
129 }
130
131 // Returns 0 if this is not a scrolling region.
132 15663568 int get_region_id(int map, int screen)
133 {
134
2/2
✓ Branch 0 taken 401435 times.
✓ Branch 1 taken 15262133 times.
15663568 if (screen >= 128) return 0;
135
2/2
✓ Branch 0 taken 15261033 times.
✓ Branch 1 taken 1100 times.
15262133 if (map == cur_region.map) return current_region_ids[screen];
136
137 1100 return Regions[map].get_region_id(screen);
138 15663568 }
139
140 982758 int get_current_region_id()
141 {
142 982758 return get_region_id(cur_map, cur_screen);
143 }
144
145 64218 void calculate_region(int map, int screen, region_t& region, int& region_scr_dx, int& region_scr_dy)
146 {
147 64218 region.map = map;
148
149
2/2
✓ Branch 0 taken 63944 times.
✓ Branch 1 taken 274 times.
64218 if (!is_in_scrolling_region(map, screen))
150 {
151 63944 region.region_id = 0;
152 63944 region.origin_screen = screen;
153 63944 region.origin_screen_x = screen % 16;
154 63944 region.origin_screen_y = screen / 16;
155 63944 region.screen_width = 1;
156 63944 region.screen_height = 1;
157 63944 region.screen_count = 1;
158 63944 region.width = 256;
159 63944 region.height = 176;
160 63944 region_scr_dx = 0;
161 63944 region_scr_dy = 0;
162 63944 return;
163 }
164
165 274 int input_scr_x = screen % 16;
166 274 int input_scr_y = screen / 16;
167
168 // For the given screen, find the top-left corner of its region.
169 274 int origin_scr_x = input_scr_x;
170 274 int origin_scr_y = input_scr_y;
171 274 int origin_scr = screen;
172
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 372 times.
434 while (origin_scr_x > 0)
173 {
174
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 160 times.
372 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x - 1, origin_scr_y))) break;
175 160 origin_scr_x--;
176 }
177
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 414 times.
508 while (origin_scr_y > 0)
178 {
179
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 234 times.
414 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x, origin_scr_y - 1))) break;
180 234 origin_scr_y--;
181 }
182 274 origin_scr = map_scr_xy_to_index(origin_scr_x, origin_scr_y);
183
184 // Now find the bottom-right corner.
185 274 int region_scr_right = origin_scr_x;
186
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 614 times.
642 while (region_scr_right < 15)
187 {
188
2/2
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 368 times.
614 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(region_scr_right + 1, origin_scr_y))) break;
189 368 region_scr_right++;
190 }
191 274 int region_scr_bottom = origin_scr_y;
192
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 832 times.
856 while (region_scr_bottom < 7)
193 {
194
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 582 times.
832 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x, region_scr_bottom + 1))) break;
195 582 region_scr_bottom++;
196 }
197
198 274 region.region_id = get_region_id(map, origin_scr);
199 274 region.origin_screen = origin_scr;
200 274 region.origin_screen_x = origin_scr_x;
201 274 region.origin_screen_y = origin_scr_y;
202 274 region.screen_width = region_scr_right - origin_scr_x + 1;
203 274 region.screen_height = region_scr_bottom - origin_scr_y + 1;
204 274 region.screen_count = region.screen_width * region.screen_height;
205 274 region.width = 256 * region.screen_width;
206 274 region.height = 176 * region.screen_height;
207 274 region_scr_dx = input_scr_x - origin_scr_x;
208 274 region_scr_dy = input_scr_y - origin_scr_y;
209
210 DCHECK_RANGE_INCLUSIVE(region.screen_width, 0, 16);
211 DCHECK_RANGE_INCLUSIVE(region.screen_height, 0, 8);
212 64218 }
213
214 35857 void load_region(int dmap, int screen)
215 {
216 35857 clear_temporary_screens();
217
218 35857 int map = DMaps[dmap].map;
219 35857 current_region_ids = Regions[map].get_all_region_ids();
220
221 35857 calculate_region(map, screen, cur_region, region_scr_dx, region_scr_dy);
222 35857 cur_screen = cur_region.origin_screen;
223 35857 world_w = cur_region.width;
224 35857 world_h = cur_region.height;
225 35857 region_scr_count = cur_region.screen_count;
226 35857 region_max_rpos = (rpos_t)(cur_region.screen_count*176 - 1);
227 35857 region_num_rpos = cur_region.screen_count*176;
228 35857 scrolling_maze_last_solved_screen = 0;
229
230 35857 memset(screen_in_current_region, false, sizeof(screen_in_current_region));
231
2/2
✓ Branch 0 taken 36091 times.
✓ Branch 1 taken 35857 times.
71948 for (int x = 0; x < cur_region.screen_width; x++)
232 {
233
2/2
✓ Branch 0 taken 37101 times.
✓ Branch 1 taken 36091 times.
73192 for (int y = 0; y < cur_region.screen_height; y++)
234 {
235 37101 int screen = cur_screen + x + y*16;
236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37101 times.
37101 if (screen < 136)
237 {
238 37101 screen_in_current_region[screen] = true;
239 37101 }
240 37101 }
241 36091 }
242
243 35857 mark_current_region_handles_dirty();
244 35857 }
245
246 35857 static void prepare_current_region_handles()
247 {
248 35857 current_region_rpos_handles_dirty = false;
249 35857 current_region_screen_count = 0;
250
2/2
✓ Branch 0 taken 36205 times.
✓ Branch 1 taken 35857 times.
72062 for (int y = 0; y < cur_region.screen_height; y++)
251 {
252
2/2
✓ Branch 0 taken 37101 times.
✓ Branch 1 taken 36205 times.
73306 for (int x = 0; x < cur_region.screen_width; x++)
253 {
254 37101 int screen = cur_screen + x + y*16;
255 37101 int index_start = current_region_screen_count;
256
2/2
✓ Branch 0 taken 37101 times.
✓ Branch 1 taken 259707 times.
296808 for (int layer = 0; layer <= 6; layer++)
257 {
258 259707 mapscr* scr = get_scr_layer(screen, layer);
259
2/2
✓ Branch 0 taken 86190 times.
✓ Branch 1 taken 173517 times.
259707 if (!scr->is_valid())
260 {
261
1/2
✓ Branch 0 taken 173517 times.
✗ Branch 1 not taken.
173517 if (layer == 0) break;
262 173517 continue;
263 }
264
265 86190 rpos_t base_rpos = POS_TO_RPOS(0, get_region_relative_dx(screen), get_region_relative_dy(screen));
266 86190 current_region_rpos_handles[current_region_screen_count] = {scr, screen, layer, base_rpos, 0};
267 86190 current_region_screen_count += 1;
268 86190 }
269
270 37101 int num_handles_for_scr = current_region_screen_count - index_start;
271 37101 current_region_rpos_handles_scr[screen] = {&current_region_rpos_handles[index_start], num_handles_for_scr};
272 37101 }
273 36205 }
274 35857 }
275
276 1635707434 std::tuple<const rpos_handle_t*, int> get_current_region_handles()
277 {
278 DCHECK(!current_region_rpos_handles_dirty);
279 1635707434 return {current_region_rpos_handles, current_region_screen_count};
280 }
281
282 11134672 std::tuple<const rpos_handle_t*, int> get_current_region_handles(mapscr* scr)
283 {
284 DCHECK(!current_region_rpos_handles_dirty);
285
2/4
✓ Branch 0 taken 11134672 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11134672 times.
11134672 if (scr == special_warp_return_scr || current_region_rpos_handles_dirty)
286 return {nullptr, 0};
287
288
2/2
✓ Branch 0 taken 65877 times.
✓ Branch 1 taken 11068795 times.
11134672 if (cur_screen >= 0x80)
289 {
290 DCHECK(scr == origin_scr);
291 65877 return {nullptr, 0};
292 }
293
294 DCHECK(is_in_current_region(scr));
295 11068795 return current_region_rpos_handles_scr[scr->screen];
296 11134672 }
297
298 35857 void mark_current_region_handles_dirty()
299 {
300 35857 current_region_rpos_handles_dirty = true;
301 35857 }
302
303 64946 void delete_temporary_screens(mapscr** screens)
304 {
305
2/2
✓ Branch 0 taken 61828592 times.
✓ Branch 1 taken 64946 times.
61893538 for (int i = 0; i < 136*7; i++)
306 {
307
2/2
✓ Branch 0 taken 255696 times.
✓ Branch 1 taken 61572896 times.
61828592 if (!screens[i])
308 61572896 continue;
309
310 255696 mapscr* scr = screens[i];
311 255696 int num_ffcs = scr->numFFC();
312
2/2
✓ Branch 0 taken 7619704 times.
✓ Branch 1 taken 255696 times.
7875400 for (int i = 0; i < num_ffcs; i++)
313 {
314 7619704 sprite* ffc = &scr->ffcs[i];
315
2/2
✓ Branch 0 taken 7617847 times.
✓ Branch 1 taken 1857 times.
7619704 if (ffc->uid)
316 1857 FFCore.release_sprite_owned_objects(ffc->uid);
317 7619704 }
318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 255696 times.
255696 delete scr;
319 255696 screens[i] = NULL;
320 255696 }
321 64946 }
322
323 36996 void clear_temporary_screens()
324 {
325 36996 delete_temporary_screens(temporary_screens);
326 36996 origin_scr = nullptr;
327 36996 hero_scr = nullptr;
328 36996 }
329
330 27954 std::vector<mapscr*> take_temporary_scrs()
331 {
332
1/2
✓ Branch 0 taken 27954 times.
✗ Branch 1 not taken.
27954 std::vector<mapscr*> screens(temporary_screens, temporary_screens + 136*7);
333
2/2
✓ Branch 0 taken 27954 times.
✓ Branch 1 taken 26612208 times.
26640162 for (int i = 0; i < 136*7; i++)
334 26612208 temporary_screens[i] = nullptr;
335
336 27954 return screens;
337
1/2
✓ Branch 0 taken 27954 times.
✗ Branch 1 not taken.
27954 }
338
339 14555436 void calculate_viewport(viewport_t& viewport, int dmap, int screen, int world_w, int world_h, int x, int y)
340 {
341 // TODO: In future, maybe add x/y centering offsets to zscript (Viewport->TargetXOffset/Viewport->TargetYOffset).
342
343
2/2
✓ Branch 0 taken 14508854 times.
✓ Branch 1 taken 46582 times.
14555436 bool extended_height_mode = (DMaps[dmap].flags & dmfEXTENDEDVIEWPORT) && world_h > 176;
344 14555436 viewport.w = 256;
345 14555436 viewport.h = 176 + (extended_height_mode ? 56 : 0);
346
347
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 14555076 times.
14555436 if (viewport_mode == ViewportMode::Script)
348 360 return;
349
350
2/2
✓ Branch 0 taken 46162 times.
✓ Branch 1 taken 14508914 times.
14555076 if (!is_in_scrolling_region(DMaps[dmap].map, screen))
351 {
352 14508914 viewport.x = 0;
353 14508914 viewport.y = 0;
354 14508914 }
355
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46162 times.
46162 else if (viewport_mode == ViewportMode::CenterAndBound)
356 {
357 // Clamp the viewport to the edges of the region.
358
6/6
✓ Branch 0 taken 8568 times.
✓ Branch 1 taken 37594 times.
✓ Branch 2 taken 6788 times.
✓ Branch 3 taken 39374 times.
✓ Branch 4 taken 8568 times.
✓ Branch 5 taken 30806 times.
46162 viewport.x = CLAMP(0, world_w - viewport.w, x - viewport.w/2);
359
6/6
✓ Branch 0 taken 11856 times.
✓ Branch 1 taken 34306 times.
✓ Branch 2 taken 5650 times.
✓ Branch 3 taken 40512 times.
✓ Branch 4 taken 11856 times.
✓ Branch 5 taken 28656 times.
46162 viewport.y = CLAMP(0, world_h - viewport.h, y - viewport.h/2);
360 46162 }
361 else if (viewport_mode == ViewportMode::Center)
362 {
363 viewport.x = x - viewport.w/2;
364 viewport.y = y - viewport.h/2;
365 }
366 14555436 }
367
368 14554925 sprite* get_viewport_sprite()
369 {
370 14554925 sprite* spr = sprite::getByUID(viewport_sprite_uid);
371
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 14554919 times.
14554925 if (!spr)
372 {
373 6 viewport_sprite_uid = 1; // Hero uid.
374 6 spr = &Hero;
375 6 }
376
377 14554925 return spr;
378 }
379
380 6 void set_viewport_sprite(sprite* spr)
381 {
382 6 viewport_sprite_uid = spr->uid;
383 6 }
384
385 14526971 void update_viewport()
386 {
387 14526971 sprite* spr = get_viewport_sprite();
388 14526971 int x = spr->x + spr->txsz*16/2;
389 14526971 int y = spr->y + spr->tysz*16/2;
390 14526971 calculate_viewport(viewport, cur_dmap, cur_screen, world_w, world_h, x, y);
391 14526971 }
392
393 // TODO: should add a moveflag to sprites to configure the size of this rect (or effectively disable
394 // freezing if the rect returns is large enough). See:
395 // https://discord.com/channels/876899628556091432/1358483603700449581
396 // https://discord.com/channels/876899628556091432/1130384911983980554
397 //
398 85898971 viewport_t get_sprite_freeze_rect()
399 {
400 85898971 viewport_t freeze_rect = viewport;
401 85898971 int tile_buffer = 3;
402 85898971 freeze_rect.w += 16 * tile_buffer * 2;
403 85898971 freeze_rect.h += 16 * tile_buffer * 2;
404 85898971 freeze_rect.x -= 16 * tile_buffer;
405 85898971 freeze_rect.y -= 16 * tile_buffer;
406 85898971 return freeze_rect;
407 }
408
409 4722 mapscr* determine_hero_screen_from_coords()
410 {
411 4722 int x = vbound(Hero.getX().getInt(), 0, world_w - 1);
412 4722 int y = vbound(Hero.getY().getInt(), 0, world_h - 1);
413 4722 int dx = x / 256;
414 4722 int dy = y / 176;
415 4722 return get_scr(cur_screen + dx + dy * 16);
416 }
417
418 26924 bool edge_of_region(direction dir)
419 {
420
2/2
✓ Branch 0 taken 26844 times.
✓ Branch 1 taken 80 times.
26924 if (!is_in_scrolling_region()) return true;
421
422 80 int screen_x = Hero.current_screen % 16;
423 80 int screen_y = Hero.current_screen / 16;
424
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 2 times.
80 if (dir == up) screen_y -= 1;
425
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 10 times.
80 if (dir == down) screen_y += 1;
426
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 30 times.
80 if (dir == left) screen_x -= 1;
427
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 38 times.
80 if (dir == right) screen_x += 1;
428
4/8
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 80 times.
✗ Branch 7 not taken.
80 if (screen_x < 0 || screen_x > 16 || screen_y < 0 || screen_y > 8) return true;
429 80 return !is_in_current_region(map_scr_xy_to_index(screen_x, screen_y));
430 26924 }
431
432 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
433 // Coordinates are clamped to the world bounds.
434 321862847 int get_screen_for_world_xy(int x, int y)
435 {
436
2/2
✓ Branch 0 taken 300723867 times.
✓ Branch 1 taken 21138980 times.
321862847 if (!is_in_scrolling_region())
437 300723867 return cur_screen;
438
439 21138980 int dx = std::clamp(x, 0, world_w - 1) / 256;
440 21138980 int dy = std::clamp(y, 0, world_h - 1) / 176;
441 21138980 int origin_screen_x = cur_screen % 16;
442 21138980 int origin_screen_y = cur_screen / 16;
443 21138980 int scr_x = origin_screen_x + dx;
444 21138980 int scr_y = origin_screen_y + dy;
445 21138980 return map_scr_xy_to_index(scr_x, scr_y);
446 321862847 }
447
448 31102052 int get_screen_for_rpos(rpos_t rpos)
449 {
450 31102052 int origin_screen_x = cur_screen % 16;
451 31102052 int origin_screen_y = cur_screen / 16;
452 31102052 int screen = static_cast<int32_t>(rpos) / 176;
453 31102052 int scr_x = origin_screen_x + screen%cur_region.screen_width;
454 31102052 int scr_y = origin_screen_y + screen/cur_region.screen_width;
455 31102052 return map_scr_xy_to_index(scr_x, scr_y);
456 }
457
458 775826616 rpos_handle_t get_rpos_handle(rpos_t rpos, int layer)
459 {
460 DCHECK_LAYER_ZERO_INDEX(layer);
461
2/2
✓ Branch 0 taken 744862524 times.
✓ Branch 1 taken 30964092 times.
775826616 if (!is_in_scrolling_region())
462 744862524 return {get_scr_layer(cur_screen, layer), cur_screen, layer, rpos, RPOS_TO_POS(rpos)};
463 30964092 int screen = get_screen_for_rpos(rpos);
464 30964092 mapscr* scr = get_scr_layer(screen, layer);
465 30964092 return {scr, screen, layer, rpos, RPOS_TO_POS(rpos)};
466 775826616 }
467
468 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
469 // Coordinates are clamped to the world bounds.
470 3125015139 rpos_handle_t get_rpos_handle_for_world_xy(int x, int y, int layer)
471 {
472 3125015139 x = std::clamp(x, 0, world_w - 1);
473 3125015139 y = std::clamp(y, 0, world_h - 1);
474
475 DCHECK_LAYER_ZERO_INDEX(layer);
476
2/2
✓ Branch 0 taken 3098672677 times.
✓ Branch 1 taken 26342462 times.
3125015139 if (!is_in_scrolling_region())
477 {
478 3098672677 int pos = COMBOPOS(x, y);
479 3098672677 return {get_scr_layer(cur_screen, layer), cur_screen, layer, (rpos_t)pos, pos};
480 }
481 26342462 return get_rpos_handle(COMBOPOS_REGION(x, y), layer);
482 3125015139 }
483
484 // Return a rpos_handle_t for a screen-specific `pos` (0-175).
485 1926 rpos_handle_t get_rpos_handle_for_screen(int screen, int layer, int pos)
486 {
487 DCHECK_LAYER_ZERO_INDEX(layer);
488 1926 return {get_scr_layer(screen, layer), screen, layer, POS_TO_RPOS(pos, screen), pos};
489 }
490
491 // Return a rpos_handle_t for a screen-specific `pos` (0-175).
492 // Use this instead of the other `get_pos_handle_for_screen` if you already have a reference to the screen.
493 62247 rpos_handle_t get_rpos_handle_for_scr(mapscr* scr, int layer, int pos)
494 {
495 DCHECK_LAYER_ZERO_INDEX(layer);
496 62247 return {scr, scr->screen, layer, POS_TO_RPOS(pos, scr->screen), pos};
497 }
498
499 25204673 void change_rpos_handle_layer(rpos_handle_t& rpos_handle, int layer)
500 {
501 DCHECK_LAYER_ZERO_INDEX(layer);
502 25204673 rpos_handle.layer = layer;
503 25204673 rpos_handle.scr = get_scr_layer(rpos_handle.screen, layer);
504 25204673 }
505
506 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
507 // Coordinates are clamped to the world bounds.
508 52808 combined_handle_t get_combined_handle_for_world_xy(int x, int y, int layer)
509 {
510 DCHECK_LAYER_ZERO_INDEX(layer);
511
512 52808 x = std::clamp(x, 0, world_w - 1);
513 52808 y = std::clamp(y, 0, world_h - 1);
514
515 52808 auto maybe_ffc_handle = getFFCAt(x, y);
516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52808 times.
52808 if (maybe_ffc_handle)
517 return maybe_ffc_handle.value();
518
519 52808 auto rpos = COMBOPOS_REGION_B(x, y);
520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52808 times.
52808 if (rpos == rpos_t::None)
521 return rpos_handle_t();
522 52808 return get_rpos_handle(rpos, layer);
523 52808 }
524
525 // These functions all return _temporary_ screens. Any modifications made to them (either by the engine
526 // directly or via zscript) only last until the next area is loaded (via loadscr).
527
528 // Returns the screen containing the (x, y) world position.
529 1407906939 mapscr* get_scr_for_world_xy(int x, int y)
530 {
531 // Quick path, but should work the same without.
532
2/2
✓ Branch 0 taken 1397467579 times.
✓ Branch 1 taken 10439360 times.
1407906939 if (!is_in_scrolling_region()) return origin_scr;
533 10439360 return get_scr(get_screen_for_world_xy(x, y));
534 1407906939 }
535
536 24525309 mapscr* get_scr_for_rpos(rpos_t rpos)
537 {
538 // Quick path, but should work the same without.
539
2/2
✓ Branch 0 taken 24387363 times.
✓ Branch 1 taken 137946 times.
24525309 if (!is_in_scrolling_region()) return origin_scr;
540 137946 return get_scr(get_screen_for_rpos(rpos));
541 24525309 }
542
543 14 mapscr* get_scr_for_rpos_layer(rpos_t rpos, int layer)
544 {
545 14 return get_scr_layer(get_screen_for_rpos(rpos), layer);
546 }
547
548 // Note: layer=0 is the base screen, 1 is the first layer, etc.
549 2016369101 mapscr* get_scr_for_world_xy_layer(int x, int y, int layer)
550 {
551 DCHECK_LAYER_ZERO_INDEX(layer);
552
2/2
✓ Branch 0 taken 2006323887 times.
✓ Branch 1 taken 10045214 times.
2016369101 if (!is_in_scrolling_region()) return get_scr_layer(cur_screen, layer);
553
2/2
✓ Branch 0 taken 708934 times.
✓ Branch 1 taken 9336280 times.
10045214 return layer == 0 ?
554 708934 get_scr_for_world_xy(x, y) :
555 9336280 get_scr_layer(get_screen_for_world_xy(x, y), layer);
556 2016369101 }
557
558 1681778539 int get_region_screen_offset(int screen)
559 {
560 1681778539 return get_region_relative_dx(screen) + get_region_relative_dy(screen) * cur_region.screen_width;
561 }
562
563 654679296 int get_screen_for_region_index_offset(int offset)
564 {
565 654679296 int scr_dx = offset % cur_region.screen_width;
566 654679296 int scr_dy = offset / cur_region.screen_width;
567 654679296 int screen = cur_screen + scr_dx + scr_dy*16;
568 654679296 return screen;
569 }
570
571 654495459 mapscr* get_scr_for_region_index_offset(int offset)
572 {
573 654495459 int screen = get_screen_for_region_index_offset(offset);
574 654495459 return get_scr(screen);
575 }
576
577 // The screen at (map, screen) must exist.
578 1503502444 mapscr* get_scr(int map, int screen)
579 {
580 1503502444 mapscr* scr = get_scr_maybe(map, screen);
581
1/2
✓ Branch 0 taken 1503502444 times.
✗ Branch 1 not taken.
1503502444 CHECK(scr);
582 1503502444 return scr;
583 }
584
585 837704782 mapscr* get_scr(int screen)
586 {
587 837704782 return get_scr(cur_map, screen);
588 }
589
590 // Returns null if active screen does not exist.
591 1679414904 mapscr* get_scr_maybe(int map, int screen)
592 {
593 DCHECK_RANGE_INCLUSIVE(screen, 0, 135);
594
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1679414904 times.
1679414904 if (map == cur_map)
596 {
597
2/2
✓ Branch 0 taken 1658948300 times.
✓ Branch 1 taken 20466604 times.
1679414904 if (screen == cur_screen)
598 1658948300 return origin_scr;
599
600 20466604 int index = screen*7;
601
2/2
✓ Branch 0 taken 20455512 times.
✓ Branch 1 taken 11092 times.
20466604 if (temporary_screens[index])
602 20455512 return temporary_screens[index];
603
604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11092 times.
11092 if (screen == home_screen)
605 return special_warp_return_scr;
606 11092 }
607
608
4/6
✓ Branch 0 taken 11090 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 11090 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11090 times.
11092 if (screenscrolling && map == scrolling_map && !FFCore.ScrollingScreensAll.empty())
609 {
610 11090 int index = screen*7;
611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11090 times.
11090 if (FFCore.ScrollingScreensAll[index])
612 11090 return FFCore.ScrollingScreensAll[index];
613 }
614
615 2 return nullptr;
616 1679414904 }
617
618 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
619 6397064958 mapscr* get_scr_layer(int map, int screen, int layer)
620 {
621 DCHECK_LAYER_ZERO_INDEX(layer);
622
2/2
✓ Branch 0 taken 5734200061 times.
✓ Branch 1 taken 662864897 times.
6397064958 if (layer == 0)
623 662864897 return get_scr(map, screen);
624
625
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5734200061 times.
5734200061 if (map == cur_map)
626 {
627 5734200061 int index = screen*7 + layer;
628
2/2
✓ Branch 0 taken 5734131661 times.
✓ Branch 1 taken 68400 times.
5734200061 if (temporary_screens[index])
629 5734131661 return temporary_screens[index];
630
631
2/2
✓ Branch 0 taken 1860 times.
✓ Branch 1 taken 66540 times.
68400 if (screen == home_screen)
632 1860 return &special_warp_return_scrs[layer];
633 66540 }
634
635
1/2
✓ Branch 0 taken 66540 times.
✗ Branch 1 not taken.
66540 if (screenscrolling && map == scrolling_map && !FFCore.ScrollingScreensAll.empty())
636 {
637 66540 int index = screen*7 + layer;
638
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66540 times.
66540 if (FFCore.ScrollingScreensAll[index])
639 66540 return FFCore.ScrollingScreensAll[index];
640 }
641
642 NOTREACHED();
643 6397064958 }
644
645 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
646 5997701823 mapscr* get_scr_layer(int screen, int layer)
647 {
648 5997701823 return get_scr_layer(cur_map, screen, layer);
649 }
650
651 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
652 // Return nullptr if screen is not valid.
653 397289332 mapscr* get_scr_layer_valid(int screen, int layer)
654 {
655
2/2
✓ Branch 0 taken 82256272 times.
✓ Branch 1 taken 315033060 times.
397289332 if (mapscr* scr = get_scr_layer(cur_map, screen, layer); scr->is_valid())
656 82256272 return scr;
657 315033060 return nullptr;
658 397289332 }
659
660 401 mapscr* get_scr_current_region_dir(int screen, direction dir)
661 {
662 401 int x = get_region_relative_dx(screen);
663 401 int y = get_region_relative_dy(screen);
664
3/4
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 330 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 71 times.
401 if (dir == left && x == 0)
665 71 return nullptr;
666
3/4
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 238 times.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
330 if (dir == right && x == 15)
667 return nullptr;
668
3/4
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 281 times.
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
330 if (dir == down && y == 7)
669 return nullptr;
670
3/4
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 141 times.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
330 if (dir == up && y == 0)
671 189 return nullptr;
672
673 141 screen = screen_index_direction(screen, dir);
674
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 141 times.
141 if (is_in_current_region(screen))
675 return get_scr(screen);
676
677 141 return nullptr;
678 401 }
679
680 183837 ffc_handle_t get_ffc_handle(ffc_id_t id)
681 {
682 183837 uint8_t screen = get_screen_for_region_index_offset(id / MAXFFCS);
683 183837 uint8_t i = id % MAXFFCS;
684 183837 mapscr* scr = get_scr(screen);
685 183837 ffcdata* ffc = &scr->getFFC(id % MAXFFCS);
686 183837 return {scr, screen, id, i, ffc};
687 }
688
689 34566 std::pair<int32_t, int32_t> translate_screen_coordinates_to_world(int screen, int x, int y)
690 {
691 34566 x += get_region_relative_dx(screen) * 256;
692 34566 y += get_region_relative_dy(screen) * 176;
693 34566 return {x, y};
694 }
695
696 1049509 std::pair<int32_t, int32_t> translate_screen_coordinates_to_world(int screen)
697 {
698 1049509 int x = get_region_relative_dx(screen) * 256;
699 1049509 int y = get_region_relative_dy(screen) * 176;
700 1049509 return {x, y};
701 }
702
703 11573685998 int32_t COMBOPOS(int32_t x, int32_t y)
704 {
705 DCHECK(x >= 0 && x < 256 && y >= 0 && y < 176);
706 11573685998 return (y & 0xF0) + (x >> 4);
707 }
708 int32_t COMBOPOS_B(int32_t x, int32_t y)
709 {
710 if(unsigned(x) >= 256 || unsigned(y) >= 176)
711 return -1;
712 return (y & 0xF0) + (x >> 4);
713 }
714 3470913484 int32_t COMBOX(int32_t pos)
715 {
716 3470913484 return pos % 16 * 16;
717 }
718 3470913484 int32_t COMBOY(int32_t pos)
719 {
720 3470913484 return pos & 0xF0;
721 }
722
723 111281514 rpos_t COMBOPOS_REGION(int32_t x, int32_t y)
724 {
725
2/2
✓ Branch 0 taken 84123578 times.
✓ Branch 1 taken 27157936 times.
111281514 if (!is_in_scrolling_region())
726 84123578 return (rpos_t) COMBOPOS(x, y);
727
728 DCHECK(is_in_world_bounds(x, y));
729 27157936 int scr_dx = x / (16*16);
730 27157936 int scr_dy = y / (11*16);
731 27157936 int pos = COMBOPOS(x%256, y%176);
732 27157936 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + pos);
733 111281514 }
734 6437054483 rpos_t COMBOPOS_REGION_B(int32_t x, int32_t y)
735 {
736
2/2
✓ Branch 0 taken 1400968 times.
✓ Branch 1 taken 6435653515 times.
6437054483 if (!is_in_world_bounds(x, y))
737 1400968 return rpos_t::None;
738
739 6435653515 int scr_dx = x / (16*16);
740 6435653515 int scr_dy = y / (11*16);
741 6435653515 int pos = COMBOPOS(x%256, y%176);
742 6435653515 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + pos);
743 6437054483 }
744 26543341 std::pair<int32_t, int32_t> COMBOXY_REGION(rpos_t rpos)
745 {
746 26543341 int scr_index = static_cast<int32_t>(rpos) / 176;
747 26543341 int scr_dx = scr_index % cur_region.screen_width;
748 26543341 int scr_dy = scr_index / cur_region.screen_width;
749 26543341 int pos = RPOS_TO_POS(rpos);
750 26543341 int x = scr_dx*16*16 + COMBOX(pos);
751 26543341 int y = scr_dy*11*16 + COMBOY(pos);
752 26543341 return {x, y};
753 }
754 60396 int32_t COMBOX_REGION(rpos_t rpos)
755 {
756 60396 auto [x, y] = COMBOXY_REGION(rpos);
757 60396 return x;
758 }
759 12225 int32_t COMBOY_REGION(rpos_t rpos)
760 {
761 12225 auto [x, y] = COMBOXY_REGION(rpos);
762 12225 return y;
763 }
764
765 70177 rpos_t COMBOPOS_REGION_INDEX(int32_t x, int32_t y)
766 {
767 DCHECK(is_in_world_bounds(x, y));
768
1/2
✓ Branch 0 taken 70177 times.
✗ Branch 1 not taken.
70177 if (!is_in_scrolling_region())
769 70177 return (rpos_t)(x + y * 16);
770
771 int scr_dx = x / 16;
772 int scr_dy = y / 11;
773 x %= 16;
774 y %= 11;
775 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + x + y * 16);
776 70177 }
777 70632 std::pair<int32_t, int32_t> COMBOXY_REGION_INDEX(rpos_t rpos)
778 {
779 70632 int scr_index = static_cast<int32_t>(rpos) / 176;
780 70632 int scr_dx = scr_index % cur_region.screen_width;
781 70632 int scr_dy = scr_index / cur_region.screen_width;
782 70632 int pos = RPOS_TO_POS(rpos);
783 70632 int x = scr_dx*16 + pos%16;
784 70632 int y = scr_dy*11 + pos/16;
785 70632 return {x, y};
786 }
787
788 88535232 int32_t mapind(int32_t map, int32_t scr)
789 {
790 88535232 return map * MAPSCRSNORMAL + scr;
791 }
792
793 FONT *get_zc_font(int index);
794
795 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
796 extern movingblock mblock2; //mblock[4]?
797 extern portal mirror_portal;
798
799 void Z_message_d(const char *format,...)
800 {
801 #ifdef _DEBUG
802 char buf[512];
803 va_list ap;
804 va_start(ap, format);
805 vsprintf(buf, format, ap);
806 va_end(ap);
807
808 al_trace("%s",buf);
809 #else
810 format=format;
811 #endif
812 }
813
814
815
816 bool checktrigger=false;
817
818 void debugging_box(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
819 {
820 //reference/optimization: the start of the unused drawing command index can now be queried. -Gleeok
821 int32_t index = script_drawing_commands.GetNext();
822
823 if(index < 0)
824 return;
825
826 int32_t *sdci = &script_drawing_commands[index][0];
827
828 sdci[0] = RECTR;
829 sdci[1] = 30000;
830 sdci[2] = x1*10000;
831 sdci[3] = y1*10000;
832 sdci[4] = x2*10000;
833 sdci[5] = y2*10000;
834 sdci[6] = 10000;
835 sdci[7] = 10000;
836 sdci[8] = 0;
837 sdci[9] = 0;
838 sdci[10] = 0;
839 sdci[11] = 10000;
840 sdci[12] = 1280000;
841 }
842
843 void clear_dmap(word i)
844 {
845 DMaps[i].clear();
846 }
847
848 void clear_dmaps()
849 {
850 for(int32_t i=0; i<MAXDMAPS; i++)
851 {
852 clear_dmap(i);
853 }
854 }
855
856 223674527 int32_t isdungeon(int32_t dmap, int32_t screen)
857 {
858
2/2
✓ Branch 0 taken 223628847 times.
✓ Branch 1 taken 45680 times.
223674527 if (dmap < 0) dmap = cur_dmap;
859
860 // dungeons can have any dlevel above 0
861
2/2
✓ Branch 0 taken 122425082 times.
✓ Branch 1 taken 101249445 times.
223674527 if((DMaps[dmap].type&dmfTYPE) == dmDNGN)
862 {
863
2/2
✓ Branch 0 taken 9961 times.
✓ Branch 1 taken 101239484 times.
101249445 if (get_canonical_scr(cur_map, screen)->flags6&fCAVEROOM)
864 9961 return 0;
865
866 101239484 return 1;
867 }
868
869 // dlevels that aren't dungeons are caves
870
2/2
✓ Branch 0 taken 36827 times.
✓ Branch 1 taken 122388255 times.
122425082 if (get_canonical_scr(cur_map, screen)->flags6&fDUNGEONROOM)
871 36827 return 1;
872
873 122388255 return 0;
874 223674527 }
875
876 39968738 int32_t isdungeon(int32_t screen)
877 {
878 39968738 return isdungeon(cur_dmap, screen);
879 }
880
881 183578846 int32_t isdungeon()
882 {
883 183578846 return isdungeon(cur_dmap, Hero.current_screen);
884 }
885
886 88935 bool canPermSecret(int32_t dmap, int32_t screen)
887 {
888
2/2
✓ Branch 0 taken 13910 times.
✓ Branch 1 taken 75025 times.
88935 return (!isdungeon(dmap, screen) || get_qr(qr_DUNGEON_DMAPS_PERM_SECRETS));
889 }
890
891 1149560840 int32_t MAPCOMBO(int32_t x, int32_t y)
892 {
893 1149560840 x = vbound(x, 0, world_w-1);
894 1149560840 y = vbound(y, 0, world_h-1);
895 1149560840 int pos = COMBOPOS(x%256, y%176);
896 1149560840 mapscr* scr = get_scr_for_world_xy(x, y);
897 1149560840 return scr->data[pos];
898 }
899
900 //specific layers 1 to 6
901 1416543144 int32_t MAPCOMBOL(int32_t layer,int32_t x,int32_t y)
902 {
903 DCHECK(layer >= 1 && layer <= 6);
904
3/4
✓ Branch 0 taken 1396849250 times.
✓ Branch 1 taken 19693894 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1396849250 times.
1416543144 if (!is_in_world_bounds(x, y) || layer <= 0)
905 19693894 return 0;
906
907 1396849250 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
908
2/2
✓ Branch 0 taken 401408041 times.
✓ Branch 1 taken 995441209 times.
1396849250 if (!m->is_valid())
909 995441209 return 0;
910
911 401408041 int pos = COMBOPOS(x%256, y%176);
912 401408041 return m->data[pos];
913 1416543144 }
914
915 int32_t MAPCSETL(int32_t layer,int32_t x,int32_t y)
916 {
917 DCHECK(layer >= 1 && layer <= 6);
918 if (!is_in_world_bounds(x, y) || layer <= 0)
919 return 0;
920
921 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
922 if (!m->is_valid())
923 return 0;
924
925 int pos = COMBOPOS(x%256, y%176);
926 return m->cset[pos];
927 }
928
929 189308 int32_t MAPFLAGL(int32_t layer,int32_t x,int32_t y)
930 {
931 DCHECK(layer >= 1 && layer <= 6);
932
2/4
✓ Branch 0 taken 189308 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 189308 times.
189308 if (!is_in_world_bounds(x, y) || layer <= 0)
933 return 0;
934
935 189308 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
936
2/2
✓ Branch 0 taken 163782 times.
✓ Branch 1 taken 25526 times.
189308 if (!m->is_valid())
937 25526 return 0;
938
939 163782 int pos = COMBOPOS(x%256, y%176);
940 163782 return m->sflag[pos];
941 189308 }
942
943 6281 int32_t COMBOTYPEL(int32_t layer,int32_t x,int32_t y)
944 {
945 DCHECK(layer >= 1 && layer <= 6);
946
2/4
✓ Branch 0 taken 6281 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6281 times.
6281 if (!is_in_world_bounds(x, y) || layer <= 0)
947 return 0;
948
949 6281 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
950
2/2
✓ Branch 0 taken 5926 times.
✓ Branch 1 taken 355 times.
6281 if (!m->is_valid())
951 355 return 0;
952
953 5926 int pos = COMBOPOS(x%256, y%176);
954 5926 return combobuf[m->data[pos]].type;
955 6281 }
956
957 189308 int32_t MAPCOMBOFLAGL(int32_t layer,int32_t x,int32_t y)
958 {
959 DCHECK(layer >= 1 && layer <= 6);
960
2/4
✓ Branch 0 taken 189308 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 189308 times.
189308 if (!is_in_world_bounds(x, y) || layer <= 0)
961 return 0;
962
963 189308 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
964
2/2
✓ Branch 0 taken 163782 times.
✓ Branch 1 taken 25526 times.
189308 if (!m->is_valid())
965 25526 return 0;
966
967 163782 int pos = COMBOPOS(x%256, y%176);
968 163782 return combobuf[m->data[pos]].flag;
969 189308 }
970
971
972 // True if the FFC covers x, y and is not ethereal or a changer.
973 2419959022 bool ffcIsAt(const ffc_handle_t& ffc_handle, int32_t x, int32_t y)
974 {
975
2/2
✓ Branch 0 taken 746713622 times.
✓ Branch 1 taken 1673245400 times.
2419959022 if (ffc_handle.data()<=0)
976 746713622 return false;
977
978
2/2
✓ Branch 0 taken 293414542 times.
✓ Branch 1 taken 1379830858 times.
1673245400 if((ffc_handle.ffc->flags&(ffc_changer|ffc_ethereal))!=0)
979 293414542 return false;
980
981 1379830858 int32_t fx=ffc_handle.ffc->x.getInt();
982
4/4
✓ Branch 0 taken 951940347 times.
✓ Branch 1 taken 427890511 times.
✓ Branch 2 taken 845077753 times.
✓ Branch 3 taken 106862594 times.
1379830858 if(x<fx || x>fx+(ffc_handle.scr->ffEffectWidth(ffc_handle.i)-1)) // FFC sizes are weird.
983 1272968264 return false;
984
985 106862594 int32_t fy=ffc_handle.ffc->y.getInt();
986
4/4
✓ Branch 0 taken 77552449 times.
✓ Branch 1 taken 29310145 times.
✓ Branch 2 taken 58355690 times.
✓ Branch 3 taken 19196759 times.
106862594 if(y<fy || y>fy+(ffc_handle.scr->ffEffectHeight(ffc_handle.i)-1))
987 87665835 return false;
988
989 19196759 return true;
990 2419959022 }
991
992 785594793 int32_t MAPFFCOMBO(int32_t x,int32_t y)
993 {
994
2/2
✓ Branch 0 taken 11603791 times.
✓ Branch 1 taken 773991002 times.
785594793 if (auto ffc_handle = getFFCAt(x, y))
995 11603791 return ffc_handle->data();
996 773991002 return 0;
997 785594793 }
998
999 207232 int32_t MAPCSET(int32_t x, int32_t y)
1000 {
1001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 207232 times.
207232 if (!is_in_world_bounds(x, y))
1002 return 0;
1003 207232 mapscr* scr = get_scr_for_world_xy(x, y);
1004 207232 int pos = COMBOPOS(x%256, y%176);
1005 207232 return scr->cset[pos];
1006 207232 }
1007
1008 73741786 int32_t MAPFLAG(int32_t x, int32_t y)
1009 {
1010
2/2
✓ Branch 0 taken 28140 times.
✓ Branch 1 taken 73713646 times.
73741786 if (!is_in_world_bounds(x, y))
1011 28140 return 0;
1012 73713646 mapscr* scr = get_scr_for_world_xy(x, y);
1013 73713646 int pos = COMBOPOS(x%256, y%176);
1014 73713646 return scr->sflag[pos];
1015 73741786 }
1016
1017 84604792 int32_t COMBOTYPE(int32_t x,int32_t y)
1018 {
1019 84604792 int32_t b=1;
1020
2/2
✓ Branch 0 taken 54646183 times.
✓ Branch 1 taken 29958609 times.
84604792 if(x&8) b<<=2;
1021
2/2
✓ Branch 0 taken 50205001 times.
✓ Branch 1 taken 34399791 times.
84604792 if(y&8) b<<=1;
1022
1023
2/2
✓ Branch 0 taken 169202546 times.
✓ Branch 1 taken 84597493 times.
253800039 for (int32_t i = 0; i <= 1; ++i)
1024 {
1025
2/2
✓ Branch 0 taken 158746666 times.
✓ Branch 1 taken 10455880 times.
169202546 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1026 {
1027
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 158746666 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
158746666 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x, y, i)) return cNONE;
1028 158746666 }
1029 else
1030 {
1031
4/4
✓ Branch 0 taken 10451 times.
✓ Branch 1 taken 10445429 times.
✓ Branch 2 taken 3152 times.
✓ Branch 3 taken 7299 times.
10455880 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x, y, i)) return cNONE;
1032 }
1033 169195247 }
1034
1035 84597493 newcombo const& cmb = combobuf[MAPCOMBO(x,y)];
1036
5/6
✓ Branch 0 taken 2449182 times.
✓ Branch 1 taken 82148311 times.
✓ Branch 2 taken 1909096 times.
✓ Branch 3 taken 540086 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1909096 times.
84597493 if (cmb.type == cWATER && (cmb.walk&b) && ((cmb.walk>>4)&b))
1037 {
1038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1909096 times.
1909096 if(cmb.usrflags&cflag4) return cSHALLOWWATER;
1039
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1909096 times.
1909096 if(cmb.usrflags&cflag3) return cNONE;
1040 1909096 }
1041 84597493 return cmb.type;
1042 84604792 }
1043
1044 49598146 int32_t FFCOMBOTYPE(int32_t x,int32_t y)
1045 {
1046 49598146 return combobuf[MAPFFCOMBO(x,y)].type;
1047 }
1048
1049 4973688 int32_t FFORCOMBO(int32_t x, int32_t y)
1050 {
1051
2/2
✓ Branch 0 taken 58516 times.
✓ Branch 1 taken 4915172 times.
4973688 if (auto ffc_handle = getFFCAt(x, y))
1052 58516 return ffc_handle->data();
1053
1054 4915172 return MAPCOMBO(x,y);
1055 4973688 }
1056
1057 int32_t FFORCOMBOTYPE(int32_t x, int32_t y)
1058 {
1059 for (int32_t i = 0; i <= 1; ++i)
1060 {
1061 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1062 {
1063 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,i)) return cNONE;
1064 }
1065 else
1066 {
1067 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x,y,i)) return cNONE;
1068 }
1069 }
1070 int32_t b=1;
1071
1072 if(x&8) b<<=2;
1073
1074 if(y&8) b<<=1;
1075 newcombo const& cmb = combobuf[FFORCOMBO(x,y)];
1076 if (cmb.type == cWATER && (cmb.usrflags&cflag4) && (cmb.walk&b)) return cSHALLOWWATER;
1077 if (cmb.type == cWATER && (cmb.usrflags&cflag3) && (cmb.walk&b)) return cNONE;
1078 return cmb.type;
1079 }
1080
1081 int32_t FFORCOMBO_L(int32_t layer, int32_t x, int32_t y)
1082 {
1083 if (auto ffc_handle = getFFCAt(x, y))
1084 return ffc_handle->data();
1085
1086 return layer ? MAPCOMBOL(layer, x, y) : MAPCOMBO(x,y);
1087 }
1088
1089 int32_t FFORCOMBOTYPE_L(int32_t layer, int32_t x, int32_t y)
1090 {
1091 return combobuf[FFORCOMBO_L(layer,x,y)].type;
1092 }
1093
1094 70224780 int32_t MAPCOMBOFLAG(int32_t x,int32_t y)
1095 {
1096
2/2
✓ Branch 0 taken 27852 times.
✓ Branch 1 taken 70196928 times.
70224780 if (!is_in_world_bounds(x, y))
1097 27852 return 0;
1098
1099 70196928 mapscr* scr = get_scr_for_world_xy(x, y);
1100 70196928 int pos = COMBOPOS(x%256, y%176);
1101 70196928 return combobuf[scr->data[pos]].flag;
1102 70224780 }
1103
1104 57001425 int32_t MAPFFCOMBOFLAG(int32_t x,int32_t y)
1105 {
1106
2/2
✓ Branch 0 taken 746177 times.
✓ Branch 1 taken 56255248 times.
57001425 if (auto ffc_handle = getFFCAt(x, y))
1107 746177 return ffc_handle->cflag();
1108
1109 56255248 return 0;
1110 57001425 }
1111
1112 1165943107 std::optional<ffc_handle_t> getFFCAt(int32_t x, int32_t y)
1113 {
1114 2594176261 return find_ffc([&](const ffc_handle_t& ffc_handle) {
1115 1428233154 return ffcIsAt(ffc_handle, x, y);
1116 });
1117 }
1118
1119 3044 int32_t MAPCOMBO(const rpos_handle_t& rpos_handle)
1120 {
1121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3044 times.
3044 if (!rpos_handle.scr->is_valid()) return 0;
1122 3044 return rpos_handle.data();
1123 3044 }
1124
1125 2709651120 int32_t MAPCOMBO2(int32_t layer, int32_t x, int32_t y)
1126 {
1127 DCHECK_LAYER_NEG1_INDEX(layer);
1128
2/2
✓ Branch 0 taken 21695970 times.
✓ Branch 1 taken 2687955150 times.
2709651120 if (!is_in_world_bounds(x, y)) return 0;
1129
2/2
✓ Branch 0 taken 2616101571 times.
✓ Branch 1 taken 71853579 times.
2687955150 if (layer == -1) return MAPCOMBO(x, y);
1130
1131 2616101571 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1132
2/2
✓ Branch 0 taken 1772045193 times.
✓ Branch 1 taken 844056378 times.
2616101571 if (!rpos_handle.scr->is_valid()) return 0;
1133
1134 844056378 return rpos_handle.data();
1135 2709651120 }
1136
1137 17565647 static void _handle_screen_load_trigger(const combined_handle_t& handle)
1138 {
1139 17565647 auto cid = handle.data();
1140 17565647 auto* cmb = &handle.combo();
1141 17565647 bool done = false;
1142 17565647 std::set<int32_t> visited;
1143
2/2
✓ Branch 0 taken 17565647 times.
✓ Branch 1 taken 17565647 times.
35131294 while(!done)
1144 {
1145
2/4
✓ Branch 0 taken 17565647 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17565647 times.
17565647 if(visited.contains(cid))
1146 {
1147 Z_error("Combo '%d' was part of an infinite trigger loop, breaking out of loop", cid);
1148 break; // prevent infinite loop
1149 }
1150
1/2
✓ Branch 0 taken 17565647 times.
✗ Branch 1 not taken.
17565647 visited.insert(cid);
1151
1152 17565647 done = true; // don't loop again unless something changes
1153
1/2
✓ Branch 0 taken 17565647 times.
✗ Branch 1 not taken.
18442371 trig_each_combo_trigger(handle, [&](combo_trigger const& trig){
1154 876724 return trig.trigger_flags.get(TRIGFLAG_SCREENLOAD);
1155 });
1156
2/4
✓ Branch 0 taken 17565647 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17565647 times.
17565647 if(handle.data() != cid)
1157 {
1158 cid = handle.data();
1159 cmb = &handle.combo();
1160 done = false; // loop again for the new combo
1161 }
1162 }
1163 17565647 }
1164 51233 static void handle_screen_load_trigger(const screen_handles_t& screen_handles)
1165 {
1166 51233 for_every_combo_in_screen(screen_handles, _handle_screen_load_trigger);
1167 51233 }
1168 34823 void handle_region_load_trigger()
1169 {
1170
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 34671 times.
34823 if (is_in_scrolling_region())
1171 {
1172
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 19456 times.
19608 for (int screen = 0; screen < 128; screen++)
1173 {
1174
2/2
✓ Branch 0 taken 18156 times.
✓ Branch 1 taken 1300 times.
19456 if (is_in_current_region(screen))
1175 1300 handle_screen_load_trigger(create_screen_handles_one(get_scr(screen)));
1176 19456 }
1177 152 }
1178 34671 else handle_screen_load_trigger(create_screen_handles_one(get_scr(Hero.current_screen)));
1179 34823 }
1180
1181 15262 static void apply_state_changes_to_screen(mapscr& scr, int32_t map, int32_t screen, int32_t flags, bool secrets_do_replay_comment)
1182 {
1183 15262 auto screen_handles = create_screen_handles_one(&scr);
1184
1185
3/4
✓ Branch 0 taken 539 times.
✓ Branch 1 taken 14723 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 539 times.
15262 if ((flags & mSECRET) && canPermSecret(cur_dmap, screen))
1186 {
1187 539 reveal_hidden_stairs(&scr, screen, false);
1188 539 bool do_layers = false;
1189 539 bool from_active_screen = false;
1190 539 trigger_secrets_for_screen_internal(screen_handles, do_layers, from_active_screen, -3, secrets_do_replay_comment);
1191 539 }
1192
1/2
✓ Branch 0 taken 15262 times.
✗ Branch 1 not taken.
15262 if (flags & mLIGHTBEAM)
1193 {
1194 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
1195 if (rpos_handle.ctype() == cLIGHTTARGET)
1196 {
1197 if (!(rpos_handle.combo().usrflags&cflag1)) //Unlit version
1198 rpos_handle.increment_data();
1199 }
1200 });
1201 }
1202
1203 15262 int lvl = DMaps[cur_dmap].level;
1204 15262 toggle_switches(game->lvlswitches[lvl], true, screen_handles);
1205 15262 toggle_gswitches_load(screen_handles);
1206
1207
2/2
✓ Branch 0 taken 15170 times.
✓ Branch 1 taken 92 times.
15262 if(flags&mLOCKBLOCK) // if special stuff done before
1208 {
1209 92 remove_screenstatecombos2(screen_handles, false, cLOCKBLOCK, cLOCKBLOCK2);
1210 92 }
1211
1212
1/2
✓ Branch 0 taken 15262 times.
✗ Branch 1 not taken.
15262 if(flags&mBOSSLOCKBLOCK) // if special stuff done before
1213 {
1214 remove_screenstatecombos2(screen_handles, false, cBOSSLOCKBLOCK, cBOSSLOCKBLOCK2);
1215 }
1216
1217
1/2
✓ Branch 0 taken 15262 times.
✗ Branch 1 not taken.
15262 if(flags&mCHEST) // if special stuff done before
1218 {
1219 remove_screenstatecombos2(screen_handles, false, cCHEST, cCHEST2);
1220 }
1221
1222
1/2
✓ Branch 0 taken 15262 times.
✗ Branch 1 not taken.
15262 if(flags&mCHEST) // if special stuff done before
1223 {
1224 remove_screenstatecombos2(screen_handles, false, cLOCKEDCHEST, cLOCKEDCHEST2);
1225 }
1226
1227
1/2
✓ Branch 0 taken 15262 times.
✗ Branch 1 not taken.
15262 if(flags&mBOSSCHEST) // if special stuff done before
1228 {
1229 remove_screenstatecombos2(screen_handles, false, cBOSSCHEST, cBOSSCHEST2);
1230 }
1231
1232
1233 15262 int mi = mapind(map, screen);
1234 15262 clear_xdoors_mi(screen_handles, mi);
1235 15262 clear_xstatecombos_mi(screen_handles, mi);
1236
1237 15262 handle_screen_load_trigger(screen_handles);
1238 15262 }
1239
1240 40981 std::optional<mapscr> load_temp_mapscr_and_apply_secrets(int32_t map, int32_t screen, int32_t layer, bool secrets, bool secrets_do_replay_comment)
1241 {
1242
2/4
✓ Branch 0 taken 40981 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40981 times.
40981 if (map < 0 || screen < 0)
1243 return std::nullopt;
1244
1245 40981 const mapscr* source = get_canonical_scr(map, screen);
1246
2/2
✓ Branch 0 taken 39256 times.
✓ Branch 1 taken 1725 times.
40981 if (!source->is_valid())
1247 1725 return std::nullopt;
1248
1249
2/2
✓ Branch 0 taken 7936 times.
✓ Branch 1 taken 31320 times.
39256 if (layer >= 0)
1250 {
1251
2/2
✓ Branch 0 taken 23994 times.
✓ Branch 1 taken 7326 times.
31320 if (source->layermap[layer] <= 0)
1252 23994 return std::nullopt;
1253
1254 7326 source = get_canonical_scr(source->layermap[layer] - 1, source->layerscreen[layer]);
1255
1/2
✓ Branch 0 taken 7326 times.
✗ Branch 1 not taken.
7326 if (!source->is_valid())
1256 return std::nullopt;
1257 7326 }
1258
1259
1/2
✓ Branch 0 taken 15262 times.
✗ Branch 1 not taken.
15262 int flags = secrets ? game->maps[mapind(map, screen)] : 0;
1260 15262 mapscr scr = *source;
1261
1/2
✓ Branch 0 taken 15262 times.
✗ Branch 1 not taken.
15262 apply_state_changes_to_screen(scr, map, screen, flags, secrets_do_replay_comment);
1262
1263
1/2
✓ Branch 0 taken 15262 times.
✗ Branch 1 not taken.
15262 return scr;
1264 40981 }
1265
1266 14990 static int32_t MAPCOMBO3_impl(int32_t map, int32_t screen, int32_t layer, int32_t pos, bool secrets)
1267 {
1268
2/4
✓ Branch 0 taken 14990 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14990 times.
14990 if (map < 0 || screen < 0) return 0;
1269
1270
2/4
✓ Branch 0 taken 14990 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14990 times.
14990 if(pos>175 || pos < 0)
1271 return 0;
1272
1273 // TODO: consider caching this (invalidate on any modification via scripting, or anything
1274 // `apply_state_changes_to_screen` checks).
1275
4/5
✓ Branch 0 taken 4736 times.
✓ Branch 1 taken 10254 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4736 times.
✓ Branch 4 taken 10254 times.
19726 if (auto s = load_temp_mapscr_and_apply_secrets(map, screen, layer, secrets))
1276 4736 return s->data[pos];
1277
1278 10254 return 0;
1279 14990 }
1280
1281 // Read from the current temporary screens or, if (map, screen) is not loaded,
1282 // load that screen and apply the relevant secrets before evaluating the combo at that position.
1283 138101516 int32_t MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets)
1284 {
1285 DCHECK_LAYER_NEG1_INDEX(layer);
1286 DCHECK(map >= 0 && screen >= 0);
1287
1288
2/2
✓ Branch 0 taken 138086526 times.
✓ Branch 1 taken 14990 times.
138101516 if (is_in_current_region(map, screen)) return MAPCOMBO2(layer, x, y);
1289
1290 // Screen is not in the current region, so we have to load and trigger some secrets.
1291 14990 int pos = COMBOPOS(x, y);
1292 14990 return MAPCOMBO3_impl(map, screen, layer, pos, secrets);
1293 138101516 }
1294
1295 int32_t MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, rpos_t rpos, bool secrets)
1296 {
1297 DCHECK_LAYER_NEG1_INDEX(layer);
1298 DCHECK(map >= 0 && screen >= 0);
1299 DCHECK(is_valid_rpos(rpos));
1300
1301 if (is_in_current_region(map, screen)) return MAPCOMBO(get_rpos_handle(rpos, layer + 1));
1302
1303 // Screen is not currently loaded, so we have to load and trigger some secrets.
1304 return MAPCOMBO3_impl(map, screen, layer, RPOS_TO_POS(rpos), secrets);
1305 }
1306
1307 int32_t MAPCSET2(int32_t layer,int32_t x,int32_t y)
1308 {
1309 DCHECK_LAYER_NEG1_INDEX(layer);
1310 if (!is_in_world_bounds(x, y))
1311 return 0;
1312 if (layer == -1) return MAPCSET(x, y);
1313
1314 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1315 if (!rpos_handle.scr->is_valid()) return 0;
1316
1317 return rpos_handle.cset();
1318 }
1319
1320 99191052 int32_t MAPFLAG2(int32_t layer,int32_t x,int32_t y)
1321 {
1322 DCHECK_LAYER_NEG1_INDEX(layer);
1323
3/4
✓ Branch 0 taken 2164466 times.
✓ Branch 1 taken 97026586 times.
✓ Branch 2 taken 2164466 times.
✗ Branch 3 not taken.
99191052 if (!get_qr(qr_BUGGED_LAYERED_FLAGS) && (!is_in_world_bounds(x, y)))
1324 return 0;
1325
2/2
✓ Branch 0 taken 81545221 times.
✓ Branch 1 taken 17645831 times.
99191052 if (layer == -1) return MAPFLAG(x, y);
1326
1327 81545221 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1328
2/2
✓ Branch 0 taken 62697629 times.
✓ Branch 1 taken 18847592 times.
81545221 if (!rpos_handle.scr->is_valid()) return 0;
1329
1330 18847592 return rpos_handle.sflag();
1331 99191052 }
1332
1333 int32_t COMBOTYPE2(int32_t layer,int32_t x,int32_t y)
1334 {
1335 if(layer < 1)
1336 {
1337 for (int32_t i = layer+1; i <= 1; ++i)
1338 {
1339 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1340 {
1341 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,i)) return cNONE;
1342 }
1343 else
1344 {
1345 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x,y,i)) return cNONE;
1346 }
1347 }
1348 }
1349 if(layer==-1) return COMBOTYPE(x,y);
1350
1351 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1352 if (!rpos_handle.scr->is_valid()) return 0;
1353
1354 return rpos_handle.ctype();
1355 }
1356
1357 // Returns the flag for the combo at the given position.
1358 // This is also known as an "inherent flag".
1359 97414280 int32_t MAPCOMBOFLAG2(int32_t layer,int32_t x,int32_t y)
1360 {
1361 DCHECK_LAYER_NEG1_INDEX(layer);
1362
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 97413992 times.
97414280 if (!is_in_world_bounds(x, y))
1363 288 return 0;
1364
2/2
✓ Branch 0 taken 81486634 times.
✓ Branch 1 taken 15927358 times.
97413992 if (layer == -1) return MAPCOMBOFLAG(x, y);
1365
1366 81486634 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1367
2/2
✓ Branch 0 taken 62716507 times.
✓ Branch 1 taken 18770127 times.
81486634 if (!rpos_handle.scr->is_valid()) return 0;
1368
1369 18770127 return rpos_handle.cflag();
1370 97414280 }
1371
1372 11686167 bool HASFLAG(int32_t flag, int32_t layer, rpos_t rpos)
1373 {
1374 DCHECK_LAYER_ZERO_INDEX(layer);
1375 11686167 auto rpos_handle = get_rpos_handle(rpos, layer);
1376
2/2
✓ Branch 0 taken 4465414 times.
✓ Branch 1 taken 7220753 times.
11686167 if (!rpos_handle.scr->is_valid()) return false;
1377
2/2
✓ Branch 0 taken 4565 times.
✓ Branch 1 taken 7216188 times.
7220753 if (rpos_handle.sflag() == flag) return true;
1378
2/2
✓ Branch 0 taken 37705 times.
✓ Branch 1 taken 7178483 times.
7216188 if (rpos_handle.cflag() == flag) return true;
1379 7178483 return false;
1380 11686167 }
1381
1382 1705537 bool HASFLAG_ANY(int32_t flag, rpos_t rpos)
1383 {
1384 DCHECK(is_valid_rpos(rpos));
1385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1705537 times.
1705537 if (rpos > region_max_rpos) return false;
1386
1387
2/2
✓ Branch 0 taken 11686167 times.
✓ Branch 1 taken 1663267 times.
13349434 for(auto q = 0; q < 7; ++q)
1388 {
1389
2/2
✓ Branch 0 taken 42270 times.
✓ Branch 1 taken 11643897 times.
11686167 if(HASFLAG(flag, q, rpos))
1390 42270 return true;
1391 11643897 }
1392 1663267 return false;
1393 1705537 }
1394
1395 const char *screenstate_string[32] =
1396 {
1397 "Door Up", "Door Down", "Door Left", "Door Right", "Item", "Special Item", "Some Enemies Never Return",
1398 "Temporary No Return", "Lock Blocks", "Boss Lock Blocks", "Chests", "Locked Chests",
1399 "Boss Locked Chests", "Secrets", "Visited", "Light Beams",
1400 "All Enemies Don't Return", "<Unused>", "<Unused>", "<Unused>", "<Unused>", "<Unused>", "<Unused>", "<Unused>",
1401 "<Unused>", "<Unused>", "<Unused>", "<Unused>", "<Unused>", "<Unused>", "<Unused>", "<Unused>",
1402 };
1403
1404 34861 void eventlog_mapflags()
1405 {
1406 34861 std::ostringstream oss;
1407
1408 34861 int mi = mapind(cur_map, home_screen);
1409
1/2
✓ Branch 0 taken 34861 times.
✗ Branch 1 not taken.
34861 dword g = game->maps[mi];
1410
1411
2/4
✓ Branch 0 taken 34861 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34861 times.
✗ Branch 3 not taken.
34861 oss << fmt::format("Screen ({}, {:02X})", cur_map+1, home_screen);
1412
2/2
✓ Branch 0 taken 14514 times.
✓ Branch 1 taken 20347 times.
34861 if(g) // Main States
1413 {
1414 static const int order[] =
1415 {
1416 mSECRET, mITEM, mSPECIALITEM, mLOCKBLOCK, mBOSSLOCKBLOCK,
1417 mCHEST, mLOCKEDCHEST, mBOSSCHEST,
1418 mDOOR_UP, mDOOR_DOWN, mDOOR_LEFT, mDOOR_RIGHT,
1419 mNEVERRET, mTMPNORET, mLIGHTBEAM, mNO_ENEMIES_RETURN
1420 };
1421
1422
1/2
✓ Branch 0 taken 14514 times.
✗ Branch 1 not taken.
14514 oss << " [";
1423 14514 bool comma = false;
1424
2/2
✓ Branch 0 taken 14514 times.
✓ Branch 1 taken 232224 times.
246738 for(int fl : order)
1425 {
1426
2/2
✓ Branch 0 taken 8979 times.
✓ Branch 1 taken 223245 times.
232224 if(!(g&fl))
1427 223245 continue;
1428 8979 byte ind = byte(log2(double(fl)));
1429
2/2
✓ Branch 0 taken 1922 times.
✓ Branch 1 taken 7057 times.
8979 if(comma)
1430
1/2
✓ Branch 0 taken 1922 times.
✗ Branch 1 not taken.
1922 oss << ", ";
1431
1/2
✓ Branch 0 taken 8979 times.
✗ Branch 1 not taken.
8979 oss << screenstate_string[ind];
1432 8979 comma = true;
1433 }
1434
1/2
✓ Branch 0 taken 14514 times.
✗ Branch 1 not taken.
14514 oss << "]";
1435 14514 }
1436
3/4
✓ Branch 0 taken 34861 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 34823 times.
34861 if(game->xstates[mi]) // ExStates
1437 {
1438
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 oss << " Ex[";
1439 38 bool comma = false;
1440
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 1216 times.
1254 for(byte fl = 0; fl < 32; ++fl)
1441 {
1442
3/4
✓ Branch 0 taken 1216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 1172 times.
1216 if(game->xstates[mi] & (1<<fl))
1443 {
1444
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 38 times.
44 if(comma)
1445
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 oss << ", ";
1446
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 oss << int(fl);
1447 44 comma = true;
1448 44 }
1449 1216 }
1450
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 oss << "]";
1451 38 }
1452 { // ExDoors
1453
2/2
✓ Branch 0 taken 34861 times.
✓ Branch 1 taken 139444 times.
174305 for(int q = 0; q < 4; ++q)
1454 {
1455 139444 bool comma = false;
1456
3/4
✓ Branch 0 taken 139444 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 139442 times.
✓ Branch 3 taken 2 times.
139444 if(auto v = game->xdoors[mi][q])
1457 {
1458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(comma)
1459 oss << ",";
1460
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 else oss << " ExDoor";
1461
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 oss << "[" << dirstr[q];
1462
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 for(int fl = 0; fl < 8; ++fl)
1463
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
19 if(v & (1<<fl))
1464
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 oss << " " << int(fl);
1465
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 oss << "]";
1466 2 comma = true;
1467 2 }
1468 139444 }
1469 }
1470
2/4
✓ Branch 0 taken 34861 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 34861 times.
34861 Z_eventlog("%s\n", oss.str().c_str());
1471 34861 }
1472
1473 // set specific flag
1474 5616 void setmapflag(mapscr* scr, uint32_t flag)
1475 {
1476
2/2
✓ Branch 0 taken 5603 times.
✓ Branch 1 taken 13 times.
5616 if (scr->screen >= 0x80) scr = special_warp_return_scr;
1477 5616 int mi = mapind(cur_map, scr->screen);
1478 5616 setmapflag_mi(scr, mi, flag);
1479 5616 }
1480 57 void setmapflag_homescr(uint32_t flag)
1481 {
1482 57 int mi = mapind(cur_map, home_screen);
1483 57 setmapflag_mi(origin_scr, mi, flag);
1484 57 }
1485 2023 void setmapflag_mi(int32_t mi, uint32_t flag)
1486 {
1487 2023 byte cscr = mi&((1<<7)-1);
1488 2023 byte cmap = (mi>>7);
1489 2023 mapscr* scr = origin_scr;
1490
2/2
✓ Branch 0 taken 834 times.
✓ Branch 1 taken 1189 times.
2023 if (is_in_current_region(cmap, cscr))
1491 1189 scr = get_scr(cmap, cscr);
1492
1493 2023 setmapflag_mi(scr, mi, flag);
1494 2023 }
1495
1496 8479 static void log_state_change(int map, int screen, std::string action)
1497 {
1498
6/6
✓ Branch 0 taken 1913 times.
✓ Branch 1 taken 6566 times.
✓ Branch 2 taken 996 times.
✓ Branch 3 taken 917 times.
✓ Branch 4 taken 352 times.
✓ Branch 5 taken 644 times.
8479 if (is_in_current_region(map, screen) || (map == cur_map && screen == home_screen))
1499 6918 Z_eventlog("[Map %d, Screen %02X (current)] %s\n", map + 1, screen, action.c_str());
1500 else
1501 1561 Z_eventlog("[Map %d, Screen %02X] %s\n", map + 1, screen, action.c_str());
1502 8479 }
1503
1504 7696 void setmapflag_mi(mapscr* scr, int32_t mi, uint32_t flag)
1505 {
1506 7696 byte cscr = mi&((1<<7)-1);
1507 7696 byte cmap = (mi>>7);
1508
1509 7696 double temp=log2((double)flag);
1510
1/2
✓ Branch 0 taken 7696 times.
✗ Branch 1 not taken.
7696 const char* state_string = flag>0 ? screenstate_string[(int32_t)temp] : "<Unknown>";
1511 7696 const char* replay_state_string = state_string;
1512
2/2
✓ Branch 0 taken 7176 times.
✓ Branch 1 taken 520 times.
7696 if(temp == 6) replay_state_string = "No Return";
1513
1514
3/4
✓ Branch 0 taken 7696 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1552 times.
✓ Branch 3 taken 6144 times.
7696 if (replay_is_active() && !(game->maps[mi] & flag))
1515
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 replay_step_comment(fmt::format("map {} scr {} flag {}", cmap, cscr, replay_state_string));
1516 7696 game->maps[mi] |= flag;
1517
1/2
✓ Branch 0 taken 7696 times.
✗ Branch 1 not taken.
7696 log_state_change(cmap, cscr, fmt::format("State set: {}", state_string));
1518
1519
2/2
✓ Branch 0 taken 2507 times.
✓ Branch 1 taken 5189 times.
7696 if((scr->nocarry&flag)!=flag)
1520 {
1521 5189 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1522 5189 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1523
1524 5189 std::vector<int32_t> done;
1525
2/2
✓ Branch 0 taken 5094 times.
✓ Branch 1 taken 95 times.
5189 bool looped = (nmap==cmap+1 && nscr==cscr);
1526
1527
6/6
✓ Branch 0 taken 406 times.
✓ Branch 1 taken 5147 times.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 364 times.
✓ Branch 4 taken 364 times.
✓ Branch 5 taken 5189 times.
5553 while((nmap!=0) && !looped && !(nscr>=128))
1528 {
1529
3/4
✓ Branch 0 taken 364 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 171 times.
✓ Branch 3 taken 193 times.
364 if(!(game->maps[((nmap-1)<<7)+nscr] & flag))
1530 {
1531
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 log_state_change(nmap, nscr, "State change carried over");
1532
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 if (replay_is_active())
1533
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 replay_step_comment(fmt::format("map {} scr {} flag {} carry", nmap, nscr, replay_state_string));
1534
1/2
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
193 game->maps[((nmap-1)<<7)+nscr] |= flag;
1535 193 }
1536
1537 364 cmap=nmap;
1538 364 cscr=nscr;
1539 364 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1540 364 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1541
1542
2/2
✓ Branch 0 taken 889 times.
✓ Branch 1 taken 364 times.
1253 for(auto it = done.begin(); it != done.end(); it++)
1543 {
1544
2/2
✓ Branch 0 taken 847 times.
✓ Branch 1 taken 42 times.
889 if(*it == ((nmap-1)<<7)+nscr)
1545 42 looped = true;
1546 889 }
1547
1548
1/2
✓ Branch 0 taken 364 times.
✗ Branch 1 not taken.
364 done.push_back(((nmap-1)<<7)+nscr);
1549 }
1550 5189 }
1551 7696 }
1552
1553 void unsetmapflag_home(uint32_t flag, bool anyflag)
1554 {
1555 int mi = mapind(cur_map, home_screen);
1556 unsetmapflag_mi(origin_scr, mi, flag, anyflag);
1557 }
1558
1559 void unsetmapflag(mapscr* scr, uint32_t flag, bool anyflag)
1560 {
1561 if (scr->screen >= 0x80) scr = special_warp_return_scr;
1562 int mi = mapind(cur_map, scr->screen);
1563 unsetmapflag_mi(scr, mi, flag, anyflag);
1564 }
1565
1566 471 void unsetmapflag_mi(int32_t mi, uint32_t flag, bool anyflag)
1567 {
1568 471 byte cscr = mi&((1<<7)-1);
1569 471 byte cmap = (mi>>7);
1570 471 mapscr* scr = origin_scr;
1571
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 11 times.
471 if (is_in_current_region(cmap, cscr))
1572 11 scr = get_scr(cmap, cscr);
1573
1574 471 unsetmapflag_mi(scr, mi, flag, anyflag);
1575 471 }
1576
1577 471 void unsetmapflag_mi(mapscr* scr, int32_t mi, uint32_t flag, bool anyflag)
1578 {
1579 471 byte cscr = mi&((1<<7)-1);
1580 471 byte cmap = (mi>>7);
1581
1582
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 11 times.
471 if(anyflag)
1583 460 game->maps[mi] &= ~flag;
1584
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 else if(flag==mITEM || flag==mSPECIALITEM)
1585 {
1586 if(!(scr->flags4&fNOITEMRESET))
1587 game->maps[mi] &= ~flag;
1588 }
1589 11 else game->maps[mi] &= ~flag;
1590
1591 471 double temp=log2((double)flag);
1592
1/2
✓ Branch 0 taken 471 times.
✗ Branch 1 not taken.
471 const char* state_string = flag>0 ? screenstate_string[(int32_t)temp] : "<Unknown>";
1593
1/2
✓ Branch 0 taken 471 times.
✗ Branch 1 not taken.
471 log_state_change(cmap, cscr, fmt::format("State unset: {}", state_string));
1594
1595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 471 times.
471 if((scr->nocarry&flag)!=flag)
1596 {
1597 471 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1598 471 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1599
1600 471 std::vector<int32_t> done;
1601
2/2
✓ Branch 0 taken 466 times.
✓ Branch 1 taken 5 times.
471 bool looped = (nmap==cmap+1 && nscr==cscr);
1602
1603
6/6
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 465 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 84 times.
✓ Branch 4 taken 84 times.
✓ Branch 5 taken 471 times.
555 while((nmap!=0) && !looped && !(nscr>=128))
1604 {
1605
3/4
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 72 times.
84 if(game->maps[((nmap-1)<<7)+nscr] & flag)
1606 {
1607
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
72 log_state_change(nmap, nscr, "State change carried over");
1608
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 game->maps[((nmap-1)<<7)+nscr] &= ~flag;
1609 72 }
1610
1611 84 cmap=nmap;
1612 84 cscr=nscr;
1613 84 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1614 84 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1615
1616
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 546 times.
630 for(std::vector<int32_t>::iterator it = done.begin(); it != done.end(); it++)
1617 {
1618
2/2
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 6 times.
546 if(*it == ((nmap-1)<<7)+nscr)
1619 6 looped = true;
1620 546 }
1621
1622
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 done.push_back(((nmap-1)<<7)+nscr);
1623 }
1624 471 }
1625 471 }
1626
1627 50195360 bool getmapflag(int32_t screen, uint32_t flag)
1628 {
1629
2/2
✓ Branch 0 taken 1345925 times.
✓ Branch 1 taken 48849435 times.
50195360 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1630 50195360 return (game->maps[mi] & flag) != 0;
1631 }
1632 6233968 bool getmapflag(mapscr* scr, uint32_t flag)
1633 {
1634 6233968 return getmapflag(scr->screen, flag);
1635 }
1636
1637 40 void setxmapflag(int32_t screen, uint32_t flag)
1638 {
1639
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1640 40 setxmapflag_mi(mi, flag);
1641 40 }
1642 42 void setxmapflag_mi(int32_t mi, uint32_t flag)
1643 {
1644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if(game->xstates[mi] & flag) return;
1645 42 byte cscr = mi&((1<<7)-1);
1646 42 byte cmap = (mi>>7);
1647
1648 42 byte temp=(byte)log2((double)flag);
1649
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 log_state_change(cmap, cscr, fmt::format("ExtraState set: {}", temp));
1650
1651 42 game->xstates[mi] |= flag;
1652
1653 42 mapscr* scr = origin_scr;
1654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (is_in_current_region(cmap, cscr))
1655 42 scr = get_scr(cmap, cscr);
1656
1657
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if((scr->exstate_carry&flag)==flag)
1658 {
1659 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1660 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1661
1662 std::vector<int32_t> done;
1663 bool looped = (nmap==cmap+1 && nscr==cscr);
1664
1665 while((nmap!=0) && !looped && !(nscr>=128))
1666 {
1667 if(!(game->maps[((nmap-1)<<7)+nscr] & flag))
1668 {
1669 log_state_change(nmap, nscr, "ExState change carried over");
1670 if (replay_is_active())
1671 replay_step_comment(fmt::format("map {} scr {} exstate {} carry", nmap, nscr, temp));
1672 game->xstates[((nmap-1)<<7)+nscr] |= flag;
1673 }
1674
1675 cmap=nmap;
1676 cscr=nscr;
1677 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1678 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1679
1680 for(auto it = done.begin(); it != done.end(); it++)
1681 {
1682 if(*it == ((nmap-1)<<7)+nscr)
1683 looped = true;
1684 }
1685
1686 done.push_back(((nmap-1)<<7)+nscr);
1687 }
1688 }
1689 42 }
1690 2 void unsetxmapflag(int32_t screen, uint32_t flag)
1691 {
1692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1693 2 unsetxmapflag_mi(mi, flag);
1694 2 }
1695 2 void unsetxmapflag_mi(int32_t mi, uint32_t flag)
1696 {
1697
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(!(game->xstates[mi] & flag)) return;
1698 1 byte cscr = mi&((1<<7)-1);
1699 1 byte cmap = (mi>>7);
1700 1 byte temp=(byte)log2((double)flag);
1701
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 log_state_change(cmap, cscr, fmt::format("ExtraState unset: {}", temp));
1702 1 game->xstates[mi] &= ~flag;
1703
1704 1 mapscr* scr = origin_scr;
1705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (is_in_current_region(cmap, cscr))
1706 1 scr = get_scr(cmap, cscr);
1707
1708
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if((scr->exstate_carry&flag)==flag)
1709 {
1710 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1711 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1712
1713 std::vector<int32_t> done;
1714 bool looped = (nmap==cmap+1 && nscr==cscr);
1715
1716 while((nmap!=0) && !looped && !(nscr>=128))
1717 {
1718 if(game->maps[((nmap-1)<<7)+nscr] & flag)
1719 {
1720 log_state_change(nmap, nscr, "ExState change carried over");
1721 game->xstates[((nmap-1)<<7)+nscr] &= ~flag;
1722 }
1723
1724 cmap=nmap;
1725 cscr=nscr;
1726 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1727 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1728
1729 for(std::vector<int32_t>::iterator it = done.begin(); it != done.end(); it++)
1730 {
1731 if(*it == ((nmap-1)<<7)+nscr)
1732 looped = true;
1733 }
1734
1735 done.push_back(((nmap-1)<<7)+nscr);
1736 }
1737 }
1738 2 }
1739 64 bool getxmapflag(int32_t screen, uint32_t flag)
1740 {
1741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1742 64 return getxmapflag_mi(mi, flag);
1743 }
1744 471650382 bool getxmapflag_mi(int32_t mi, uint32_t flag)
1745 {
1746 471650382 return (game->xstates[mi] & flag) != 0;
1747 }
1748
1749 4 void setxdoor_mi(uint mi, uint dir, uint ind, bool state)
1750 {
1751
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 if(mi > game->xdoors.size() || dir > 3 || ind > 8)
1752 return;
1753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(!(game->xdoors[mi][dir] & (1<<ind)) == !state)
1754 return;
1755
1756
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 SETFLAG(game->xdoors[mi][dir], 1<<ind, state);
1757
1758 4 int cscr = mi % MAPSCRSNORMAL;
1759 4 int cmap = mi / MAPSCRSNORMAL;
1760
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (state)
1761
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 log_state_change(cmap, cscr, fmt::format("ExDoor[{}][{}] set", dirstr[dir], ind));
1762 else
1763 log_state_change(cmap, cscr, fmt::format("ExDoor[{}][{}] unset", dirstr[dir], ind));
1764 4 }
1765 471650313 bool getxdoor_mi(uint mi, uint dir, uint ind)
1766 {
1767
3/6
✓ Branch 0 taken 471650313 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 471650313 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 471650313 times.
471650313 if(mi >= game->xdoors.size() || dir >= 4 || ind >= 8)
1768 return false;
1769 471650313 return (game->xdoors[mi][dir] & (1<<ind));
1770 471650313 }
1771 9 bool getxdoor(int32_t screen, uint dir, uint ind)
1772 {
1773 9 int mi = mapind(cur_map, screen);
1774 9 return getxdoor_mi(mi,dir,ind);
1775 }
1776
1777 401 void set_doorstate_mi(uint mi, uint dir)
1778 {
1779
1/2
✓ Branch 0 taken 401 times.
✗ Branch 1 not taken.
401 if(dir >= 4)
1780 return;
1781 401 setmapflag_mi(mi, mDOOR_UP << dir);
1782
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 400 times.
401 if(auto di = nextscr_mi(mi, dir))
1783 400 setmapflag_mi(*di, mDOOR_UP << oppositeDir[dir]);
1784 401 }
1785 401 void set_doorstate(uint screen, uint dir)
1786 {
1787 401 int mi = mapind(cur_map, screen);
1788 401 set_doorstate_mi(mi, dir);
1789 401 }
1790
1791 2 void set_xdoorstate_mi(uint mi, uint dir, uint ind, bool state)
1792 {
1793
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 if(mi >= game->xdoors.size() || dir >= 4 || ind >= 8)
1794 return;
1795 2 setxdoor_mi(mi, dir, ind, state);
1796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(auto di = nextscr_mi(mi, dir))
1797 2 setxdoor_mi(*di, oppositeDir[dir], ind, state);
1798 2 }
1799
1800 2 void set_xdoorstate(int32_t screen,uint dir, uint ind, bool state)
1801 {
1802 2 int mi = mapind(cur_map, screen);
1803 2 set_xdoorstate_mi(mi, dir, ind, state);
1804 2 }
1805
1806 57 int32_t WARPCODE(int32_t dmap,int32_t screen,int32_t dw)
1807 // returns: -1 = not a warp screen
1808 // 0+ = warp screen code ( high byte=dmap, low byte=scr )
1809 {
1810 57 const mapscr *scr = get_canonical_scr(DMaps[dmap].map, screen);
1811
1812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if(scr->room!=rWARP)
1813 return -1;
1814
1815 57 int32_t ring=scr->catchall;
1816 57 int32_t size=QMisc.warp[ring].size;
1817
1818
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 if(size==0)
1819 return -2;
1820
1821 57 int32_t index=-1;
1822
1823
2/2
✓ Branch 0 taken 289 times.
✓ Branch 1 taken 57 times.
346 for(int32_t i=0; i<size; i++)
1824
6/6
✓ Branch 0 taken 230 times.
✓ Branch 1 taken 59 times.
✓ Branch 2 taken 173 times.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 173 times.
✓ Branch 5 taken 57 times.
289 if(dmap==QMisc.warp[ring].dmap[i] && screen==
1825 346 (QMisc.warp[ring].scr[i] + DMaps[dmap].xoff))
1826 57 index=i;
1827
1828
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if(index==-1)
1829 return -3;
1830
1831 57 index = (index+dw)%size;
1832 57 return (QMisc.warp[ring].dmap[index] << 8) + QMisc.warp[ring].scr[index];
1833 57 }
1834
1835 14785046 void update_combo_cycling()
1836 {
1837 14785046 auto& combo_cache = combo_caches::can_cycle;
1838
1839 static int32_t newdata[176];
1840 static int32_t newcset[176];
1841 static bool initialized=false;
1842
1843 // Just a simple bit of optimization
1844
2/2
✓ Branch 0 taken 14784733 times.
✓ Branch 1 taken 313 times.
14785046 if(!initialized)
1845 {
1846
2/2
✓ Branch 0 taken 55088 times.
✓ Branch 1 taken 313 times.
55401 for(int32_t i=0; i<176; i++)
1847 {
1848 55088 newdata[i]=-1;
1849 55088 newcset[i]=-1;
1850 55088 }
1851
1852 313 initialized=true;
1853 313 }
1854
1855 14785046 std::set<uint16_t> restartanim;
1856
1857
1/2
✓ Branch 0 taken 14785046 times.
✗ Branch 1 not taken.
29959460 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
1858 15174414 int screen = scr->screen;
1859 int32_t x;
1860
1861
2/2
✓ Branch 0 taken 2670696864 times.
✓ Branch 1 taken 15174414 times.
2685871278 for(int32_t i=0; i<176; i++)
1862 {
1863 2670696864 x=scr->data[i];
1864 2670696864 auto& mini_cmb = combo_cache.minis[x];
1865
2/2
✓ Branch 0 taken 3273932 times.
✓ Branch 1 taken 2667422932 times.
2670696864 if (!mini_cmb.can_cycle)
1866 2667422932 continue;
1867
1868 3273932 newcombo const& cmb = combobuf[x];
1869
1870 //time to restart
1871
4/4
✓ Branch 0 taken 902694 times.
✓ Branch 1 taken 2371238 times.
✓ Branch 2 taken 474434 times.
✓ Branch 3 taken 428260 times.
3273932 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1872 {
1873 428260 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428260 times.
428260 auto c = cycle_under ? scr->undercombo : cmb.nextcombo;
1875 428260 newdata[i] = c;
1876
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 428240 times.
428260 if(!(cmb.animflags & AF_CYCLENOCSET))
1877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428240 times.
428240 newcset[i] = cycle_under ? scr->undercset : cmb.nextcset;
1878
1879
2/2
✓ Branch 0 taken 427216 times.
✓ Branch 1 taken 1044 times.
428260 if(combobuf[c].animflags & AF_CYCLE)
1880 {
1881 1044 restartanim.insert(c);
1882 1044 }
1883 428260 }
1884 3273932 }
1885
1886 15174414 int rpos_base = (int)POS_TO_RPOS(0, region_scr_x, region_scr_y);
1887
2/2
✓ Branch 0 taken 2670696864 times.
✓ Branch 1 taken 15174414 times.
2685871278 for(int32_t i=0; i<176; i++)
1888 {
1889
2/2
✓ Branch 0 taken 428260 times.
✓ Branch 1 taken 2670268604 times.
2670696864 if(newdata[i]==-1)
1890 2670268604 continue;
1891
1892 428260 rpos_t rpos = (rpos_t)(rpos_base + i);
1893 428260 rpos_handle_t rpos_handle = {scr, screen, 0, rpos, i};
1894 428260 screen_combo_modify_preroutine(rpos_handle);
1895 428260 scr->data[i]=newdata[i];
1896
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 428240 times.
428260 if(newcset[i]>-1)
1897 428240 scr->cset[i]=newcset[i];
1898 428260 screen_combo_modify_postroutine(rpos_handle);
1899
1900 428260 newdata[i]=-1;
1901 428260 newcset[i]=-1;
1902 428260 }
1903
1904 15174414 word c = scr->numFFC();
1905
2/2
✓ Branch 0 taken 15174414 times.
✓ Branch 1 taken 453719779 times.
468894193 for(word i=0; i<c; i++)
1906 {
1907 453719779 ffcdata& ffc = scr->ffcs[i];
1908 453719779 auto& mini_cmb = combo_cache.minis[ffc.data];
1909
2/2
✓ Branch 0 taken 4173 times.
✓ Branch 1 taken 453715606 times.
453719779 if (!mini_cmb.can_cycle)
1910 453715606 continue;
1911
1912 4173 newcombo const& cmb = combobuf[ffc.data];
1913
1914 //time to restart
1915
4/4
✓ Branch 0 taken 611 times.
✓ Branch 1 taken 3562 times.
✓ Branch 2 taken 503 times.
✓ Branch 3 taken 108 times.
4173 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1916 {
1917 108 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1918
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 auto c = cycle_under ? scr->undercombo : cmb.nextcombo;
1919 108 zc_ffc_set(ffc, c);
1920
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!(cmb.animflags & AF_CYCLENOCSET))
1921
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 ffc.cset = cycle_under ? scr->undercset : cmb.nextcset;
1922
1923
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 60 times.
108 if(combobuf[ffc.data].animflags & AF_CYCLE)
1924 {
1925 60 restartanim.insert(ffc.data);
1926 60 }
1927 108 }
1928 4173 }
1929
1930
2/2
✓ Branch 0 taken 8418399 times.
✓ Branch 1 taken 6756015 times.
15174414 if(get_qr(qr_CMBCYCLELAYERS))
1931 {
1932
2/2
✓ Branch 0 taken 40536090 times.
✓ Branch 1 taken 6756015 times.
47292105 for(int32_t j=1; j<=6; j++)
1933 {
1934 40536090 mapscr* layer_scr = get_scr_layer_valid(screen, j);
1935
2/2
✓ Branch 0 taken 11613093 times.
✓ Branch 1 taken 28922997 times.
40536090 if (!layer_scr)
1936 28922997 continue;
1937
1938
2/2
✓ Branch 0 taken 2043904368 times.
✓ Branch 1 taken 11613093 times.
2055517461 for(int32_t i=0; i<176; i++)
1939 {
1940 2043904368 x=layer_scr->data[i];
1941 2043904368 auto& mini_cmb = combo_cache.minis[x];
1942
2/2
✓ Branch 0 taken 2230074 times.
✓ Branch 1 taken 2041674294 times.
2043904368 if (!mini_cmb.can_cycle)
1943 2041674294 continue;
1944
1945 2230074 newcombo const& cmb = combobuf[x];
1946
1947 //time to restart
1948
4/4
✓ Branch 0 taken 48416 times.
✓ Branch 1 taken 2181658 times.
✓ Branch 2 taken 37483 times.
✓ Branch 3 taken 10933 times.
2230074 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1949 {
1950 10933 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1951
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10933 times.
10933 auto c = cycle_under ? layer_scr->undercombo : cmb.nextcombo;
1952 10933 newdata[i] = c;
1953
2/2
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 10864 times.
10933 if(!(cmb.animflags & AF_CYCLENOCSET))
1954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10864 times.
10864 newcset[i] = cycle_under ? layer_scr->undercset : cmb.nextcset;
1955 69 else newcset[i] = layer_scr->cset[i];
1956
1957
2/2
✓ Branch 0 taken 950 times.
✓ Branch 1 taken 9983 times.
10933 if(combobuf[c].animflags & AF_CYCLE)
1958 {
1959 9983 restartanim.insert(c);
1960 9983 }
1961 10933 }
1962 2230074 }
1963
1964
2/2
✓ Branch 0 taken 2043904368 times.
✓ Branch 1 taken 11613093 times.
2055517461 for (int32_t i=0; i<176; i++)
1965 {
1966
2/2
✓ Branch 0 taken 2043893435 times.
✓ Branch 1 taken 10933 times.
2043904368 if(newdata[i]!=-1)
1967 {
1968 10933 layer_scr->data[i]=newdata[i];
1969
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10933 times.
10933 if(newcset[i]>-1)
1970 10933 layer_scr->cset[i]=newcset[i];
1971 10933 newdata[i]=-1;
1972 10933 newcset[i]=-1;
1973 10933 }
1974 2043904368 }
1975 11613093 }
1976 6756015 }
1977 15174414 });
1978
1979
2/2
✓ Branch 0 taken 14785046 times.
✓ Branch 1 taken 2661 times.
14787707 for (auto i : restartanim)
1980 {
1981 2661 combobuf[i].tile = combobuf[i].o_tile;
1982 2661 combobuf[i].cur_frame=0;
1983 2661 combobuf[i].aclk = 0;
1984
1/2
✓ Branch 0 taken 2661 times.
✗ Branch 1 not taken.
2661 combo_caches::drawing.refresh(i);
1985 }
1986 14785046 }
1987
1988 1213774689 bool iswater_type(int32_t type)
1989 {
1990 // return type==cOLD_WATER || type==cSWIMWARP || type==cDIVEWARP || type==cDIVEWARPB || type==cDIVEWARPC || type==cDIVEWARPD || type==cSWIMWARPB || type==cSWIMWARPC || type==cSWIMWARPD;
1991 1213774689 return (combo_class_buf[type].water!=0);
1992 }
1993
1994 bool iswater(int32_t combo)
1995 {
1996 return iswater_type(combobuf[combo].type) && !DRIEDLAKE;
1997 }
1998 1135408 int32_t iswaterexzq(int32_t combo, int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck)
1999 {
2000 1135408 return iswaterex(combo, map, screen, layer, x, y, secrets, fullcheck, LayerCheck);
2001 }
2002
2003 // (x, y) are world coordinates
2004 58798911 int32_t iswaterex_z3(int32_t combo, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck, bool ShallowCheck, bool hero, optional<combined_handle_t>* out_handle)
2005 {
2006
8/8
✓ Branch 0 taken 58752760 times.
✓ Branch 1 taken 46151 times.
✓ Branch 2 taken 58712428 times.
✓ Branch 3 taken 40332 times.
✓ Branch 4 taken 58645682 times.
✓ Branch 5 taken 66746 times.
✓ Branch 6 taken 59577 times.
✓ Branch 7 taken 58586105 times.
58798911 if (x<0 || x>=world_w || y<0 || y>=world_h)
2007 212806 return false;
2008
2009 58586105 return iswaterex(combo, cur_map, cur_screen, layer, x, y, secrets, fullcheck, LayerCheck, ShallowCheck, hero, out_handle);
2010 58798911 }
2011
2012 97348081 int32_t iswaterex(int32_t combo, int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck, bool ShallowCheck, bool hero, optional<combined_handle_t>* out_handle)
2013 {
2014 DCHECK_LAYER_NEG1_INDEX(layer);
2015 //Honestly, fullcheck is kinda useless... I made this function back when I thought it was checking the entire combo and not just a glorified x/y value.
2016 //Fullcheck makes no sense to ever be on, but hey I guess it's here in case you ever need it...
2017
2018 //Oh hey, Zoras might actually need it. Nevermind, this had a use!
2019
2/2
✓ Branch 0 taken 57498430 times.
✓ Branch 1 taken 39849651 times.
97348081 if (get_qr(qr_SMARTER_WATER))
2020 {
2021
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 57498430 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
57498430 if (DRIEDLAKE) return 0;
2022
5/6
✓ Branch 0 taken 19614429 times.
✓ Branch 1 taken 37884001 times.
✓ Branch 2 taken 6543369 times.
✓ Branch 3 taken 13071060 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6543369 times.
57498430 if (LayerCheck && (get_qr(qr_WATER_ON_LAYER_1) || get_qr(qr_WATER_ON_LAYER_2))) //LayerCheck is a bit dumber, but it lets me add this QR without having to replace all calls, again.
2023 {
2024
2/2
✓ Branch 0 taken 37866480 times.
✓ Branch 1 taken 12397710 times.
50264190 for (int32_t m = layer; m <= 1; m++)
2025 {
2026
5/6
✓ Branch 0 taken 24795420 times.
✓ Branch 1 taken 13071060 times.
✓ Branch 2 taken 12397710 times.
✓ Branch 3 taken 12397710 times.
✓ Branch 4 taken 12397710 times.
✗ Branch 5 not taken.
50264190 if (m < 0 || m == 0 && get_qr(qr_WATER_ON_LAYER_1)
2027
1/2
✓ Branch 0 taken 12397710 times.
✗ Branch 1 not taken.
24795420 || m == 1 && get_qr(qr_WATER_ON_LAYER_2))
2028 {
2029 37866480 int32_t checkwater = iswaterex(combo, map, screen, m, x, y, secrets, fullcheck, false, ShallowCheck);
2030
2/2
✓ Branch 0 taken 37193130 times.
✓ Branch 1 taken 673350 times.
37866480 if (checkwater > 0)
2031 {
2032
2/2
✓ Branch 0 taken 673292 times.
✓ Branch 1 taken 58 times.
673350 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(x, y, m+1);
2033 673350 return checkwater;
2034 }
2035 37193130 }
2036 37193130 }
2037 12397710 return 0;
2038 }
2039 else
2040 {
2041
2/2
✓ Branch 0 taken 44442043 times.
✓ Branch 1 taken 42253191 times.
86695234 for(int32_t i=(fullcheck?3:0); i>=0; i--)
2042 {
2043 44442043 int32_t tx2=((i&2)<<2)+x;
2044 44442043 int32_t ty2=((i&1)<<3)+y;
2045 44442043 int32_t b = i; //Originally b was not needed and I read off i, but then I added the boolean for fullcheck.
2046 //In which case it's just easier to change b if fullcheck is false instead of changing i and potentially screwing up the for loop.
2047
2/2
✓ Branch 0 taken 21673 times.
✓ Branch 1 taken 44420370 times.
44442043 if (!fullcheck)
2048 {
2049 44420370 tx2 = x;
2050 44420370 ty2 = y;
2051
2/2
✓ Branch 0 taken 24936960 times.
✓ Branch 1 taken 19483410 times.
44420370 if(tx2&8) b+=2;
2052
2/2
✓ Branch 0 taken 20569499 times.
✓ Branch 1 taken 23850871 times.
44420370 if(ty2&8) b+=1;
2053 44420370 }
2054
2/2
✓ Branch 0 taken 95026787 times.
✓ Branch 1 taken 43597810 times.
138624597 for (int32_t m = layer; m <= 1; m++)
2055 {
2056 95026787 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2, true)];
2057
3/6
✓ Branch 0 taken 94959232 times.
✓ Branch 1 taken 67555 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 94959232 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
95026787 if (hero && cmb.dive_under_level && (Hero.get_standing_z_state() <= -cmb.dive_under_level))
2058 continue; // dive under this layer
2059
2060
2/2
✓ Branch 0 taken 17735727 times.
✓ Branch 1 taken 77291060 times.
95026787 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2061 {
2062
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17735727 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17735727 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<b)))
2063 {
2064 return 0;
2065 }
2066 17735727 }
2067 else
2068 {
2069
4/4
✓ Branch 0 taken 179102 times.
✓ Branch 1 taken 77111958 times.
✓ Branch 2 taken 51152 times.
✓ Branch 3 taken 127950 times.
77291060 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<b)))
2070 {
2071 127950 return 0;
2072 }
2073 }
2074
2/2
✓ Branch 0 taken 17735727 times.
✓ Branch 1 taken 77163110 times.
94898837 if (get_qr(qr_NO_SOLID_SWIM))
2075 {
2076
8/14
✓ Branch 0 taken 51152 times.
✓ Branch 1 taken 77111958 times.
✓ Branch 2 taken 51152 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 716283 times.
✓ Branch 5 taken 76395675 times.
✓ Branch 6 taken 3461 times.
✓ Branch 7 taken 712822 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3461 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
77163110 if ((cmb.type != cBRIDGE || (!get_qr(qr_OLD_BRIDGE_COMBOS) && !(cmb.walk&(0x10<<b)))) && (cmb.walk&(1<<b)) && !((cmb.usrflags&cflag4) && cmb.type == cWATER && (cmb.walk&(0x10<<b)) && ShallowCheck))
2077 716283 return 0;
2078 76446827 }
2079
3/6
✓ Branch 0 taken 320361 times.
✓ Branch 1 taken 93862193 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 320361 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
94182554 if (iswater_type(cmb.type) && (cmb.walk&(1<<b)) && ((cmb.usrflags&cflag3) || (cmb.usrflags&cflag4)
2080 || (hero && current_item(itype_flippers) < cmb.attribytes[0])
2081 || (hero && ((cmb.usrflags&cflag1) && !(itemsbuf[current_item_id(itype_flippers)].flags & item_flag3)))))
2082 {
2083 if (!(ShallowCheck && (cmb.walk&(1<<b)) && (cmb.usrflags&cflag4))) return 0;
2084 }
2085 94182554 }
2086
2087 131487468 auto found_ffc_not_water = find_ffc([&](const ffc_handle_t& ffc_handle) {
2088
2/2
✓ Branch 0 taken 87361793 times.
✓ Branch 1 taken 527865 times.
87889658 if (ffcIsAt(ffc_handle, tx2, ty2))
2089 {
2090 527865 auto ty = ffc_handle.ctype();
2091
4/6
✓ Branch 0 taken 527865 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144225 times.
✓ Branch 3 taken 383640 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 144225 times.
527865 if(!combo_class_buf[ty].water && !(ShallowCheck && ty == cSHALLOWWATER))
2092 527865 return true;
2093 }
2094
2095 87361793 return false;
2096 87889658 });
2097
2/2
✓ Branch 0 taken 43069945 times.
✓ Branch 1 taken 527865 times.
43597810 if (found_ffc_not_water) return 0;
2098
2099
2/2
✓ Branch 0 taken 14673 times.
✓ Branch 1 taken 43055272 times.
43069945 if(!i)
2100 {
2101 128093144 auto found_ffc_water = find_ffc([&](const ffc_handle_t& ffc_handle) {
2102
1/2
✓ Branch 0 taken 85037872 times.
✗ Branch 1 not taken.
85037872 if (ffcIsAt(ffc_handle, tx2, ty2))
2103 {
2104 auto ty = ffc_handle.ctype();
2105 if(combo_class_buf[ty].water || (ShallowCheck && ty == cSHALLOWWATER))
2106 return true;
2107 }
2108
2109 85037872 return false;
2110 85037872 });
2111
1/2
✓ Branch 0 taken 43055272 times.
✗ Branch 1 not taken.
43055272 if (found_ffc_water)
2112 {
2113 if(out_handle) *out_handle = *found_ffc_water;
2114 return found_ffc_water->data();
2115 }
2116 43055272 }
2117
2118 43069945 int32_t checkcombo = MAPCOMBO3(map, screen, layer, tx2, ty2, secrets);
2119
2/2
✓ Branch 0 taken 43025451 times.
✓ Branch 1 taken 44494 times.
43069945 if (!(combobuf[checkcombo].walk&(1<<(b+4)))) return 0;
2120
7/12
✓ Branch 0 taken 42744821 times.
✓ Branch 1 taken 280630 times.
✓ Branch 2 taken 10867197 times.
✓ Branch 3 taken 31877624 times.
✓ Branch 4 taken 10389013 times.
✓ Branch 5 taken 478184 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 10389013 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
43025451 if (iswater_type(combobuf[checkcombo].type)||(ShallowCheck && (combobuf[checkcombo].type == cSHALLOWWATER || (iswater_type(combobuf[checkcombo].type) && (combobuf[checkcombo].walk&(1<<b)) && (combobuf[checkcombo].usrflags&cflag4)))))
2121 {
2122
2/2
✓ Branch 0 taken 1227 times.
✓ Branch 1 taken 757587 times.
758814 if (i == 0)
2123 {
2124
2/2
✓ Branch 0 taken 757578 times.
✓ Branch 1 taken 9 times.
757587 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(tx2, ty2, layer+1);
2125 757587 return checkcombo;
2126 }
2127 1227 }
2128 42267864 }
2129 42253191 return 0;
2130 }
2131 }
2132 else
2133 {
2134 39849651 int32_t b = 0;
2135
2/2
✓ Branch 0 taken 20636602 times.
✓ Branch 1 taken 19213049 times.
39849651 if(x&8) b+=2;
2136
2/2
✓ Branch 0 taken 15456675 times.
✓ Branch 1 taken 24392976 times.
39849651 if(y&8) b+=1;
2137
1/2
✓ Branch 0 taken 39849651 times.
✗ Branch 1 not taken.
39849651 if (get_qr(qr_NO_SOLID_SWIM))
2138 {
2139 if (combobuf[combo].walk&(1<<b))
2140 {
2141 return 0;
2142 }
2143 }
2144
1/2
✓ Branch 0 taken 39849651 times.
✗ Branch 1 not taken.
39849651 if (!(combobuf[combo].walk&(1<<(b+4)))) return 0;
2145
8/8
✓ Branch 0 taken 38150901 times.
✓ Branch 1 taken 1698750 times.
✓ Branch 2 taken 167945 times.
✓ Branch 3 taken 37982956 times.
✓ Branch 4 taken 2129 times.
✓ Branch 5 taken 1782338 times.
✓ Branch 6 taken 163774 times.
✓ Branch 7 taken 161691 times.
39849651 if((iswater_type(combobuf[combo].type) || (ShallowCheck && combobuf[combo].type == cSHALLOWWATER)) && !DRIEDLAKE)
2146 {
2147
2/2
✓ Branch 0 taken 1943999 times.
✓ Branch 1 taken 30 times.
1944029 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(x, y, 0); //NOTE: This is only correct assuming 'combo' is 'MAPCOMBO(x,y)'
2148 1944029 return combo;
2149 }
2150 38146730 return 0;
2151 }
2152 97589189 }
2153
2154 326 bool isdamage_type(int32_t type)
2155 {
2156
1/2
✓ Branch 0 taken 326 times.
✗ Branch 1 not taken.
326 switch(type)
2157 {
2158 case cDAMAGE1: case cDAMAGE2: case cDAMAGE3: case cDAMAGE4:
2159 case cDAMAGE5: case cDAMAGE6: case cDAMAGE7:
2160 return true;
2161 }
2162 326 return false;
2163 326 }
2164
2165 2129355884 bool ispitfall_type(int32_t type)
2166 {
2167 2129355884 return combo_class_buf[type].pit != 0;
2168 }
2169
2170 2129355884 bool ispitfall(int32_t combo)
2171 {
2172 2129355884 return ispitfall_type(combobuf[combo].type);
2173 }
2174
2175 131120024 bool ispitfall(int32_t x, int32_t y)
2176 {
2177
2/2
✓ Branch 0 taken 1274013 times.
✓ Branch 1 taken 129846011 times.
131120024 if(int32_t c = MAPFFCOMBO(x,y))
2178 {
2179 1274013 return ispitfall(c) ? true : false;
2180 }
2181 129846011 int32_t c = MAPCOMBOL(2,x,y);
2182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 129846011 times.
129846011 if(ispitfall(c)) return true;
2183
2/2
✓ Branch 0 taken 122656443 times.
✓ Branch 1 taken 7189568 times.
129846011 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2184 {
2185
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 122656443 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
122656443 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1)) return false;
2186 122656443 }
2187 else
2188 {
2189
3/4
✓ Branch 0 taken 2780 times.
✓ Branch 1 taken 7186788 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2780 times.
7189568 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1)) return false;
2190 }
2191 129843231 c = MAPCOMBOL(1,x,y);
2192
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 129843207 times.
129843231 if(ispitfall(c)) return true;
2193
2194
2/2
✓ Branch 0 taken 122656443 times.
✓ Branch 1 taken 7186764 times.
129843207 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2195 {
2196
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 122656443 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
122656443 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0)) return false;
2197 122656443 }
2198 else
2199 {
2200
4/4
✓ Branch 0 taken 13072 times.
✓ Branch 1 taken 7173692 times.
✓ Branch 2 taken 8777 times.
✓ Branch 3 taken 4295 times.
7186764 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0)) return false;
2201 }
2202 129834430 c = MAPCOMBO(x,y);
2203
2/2
✓ Branch 0 taken 56973 times.
✓ Branch 1 taken 129777457 times.
129834430 if(ispitfall(c)) return true;
2204 129777457 return false;
2205 131120024 }
2206
2207 585765195 int32_t getpitfall(int32_t x, int32_t y) //Return the highest-layer active pit combo at the given position
2208 {
2209
2/2
✓ Branch 0 taken 9281019 times.
✓ Branch 1 taken 576484176 times.
585765195 if(int32_t c = MAPFFCOMBO(x,y))
2210 {
2211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9281019 times.
9281019 return ispitfall(c) ? c : 0;
2212 }
2213 576484176 int32_t c = MAPCOMBOL(2,x,y);
2214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 576484176 times.
576484176 if(ispitfall(c)) return c;
2215
2216
2/2
✓ Branch 0 taken 532722485 times.
✓ Branch 1 taken 43761691 times.
576484176 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2217 {
2218
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 532722485 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
532722485 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1)) return 0;
2219 532722485 }
2220 else
2221 {
2222
3/4
✓ Branch 0 taken 35747 times.
✓ Branch 1 taken 43725944 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 35747 times.
43761691 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1)) return 0;
2223 }
2224 576448429 c = MAPCOMBOL(1,x,y);
2225
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 576448151 times.
576448429 if(ispitfall(c)) return c;
2226
2227
2/2
✓ Branch 0 taken 532722485 times.
✓ Branch 1 taken 43725666 times.
576448151 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2228 {
2229
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 532722485 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
532722485 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0)) return 0;
2230 532722485 }
2231 else
2232 {
2233
4/4
✓ Branch 0 taken 144357 times.
✓ Branch 1 taken 43581309 times.
✓ Branch 2 taken 103729 times.
✓ Branch 3 taken 40628 times.
43725666 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0)) return 0;
2234 }
2235 576344422 c = MAPCOMBO(x,y);
2236
2/2
✓ Branch 0 taken 176844 times.
✓ Branch 1 taken 576167578 times.
576344422 if(ispitfall(c)) return c;
2237 576167578 return 0;
2238 585765195 }
2239 51 optional<combined_handle_t> get_pitfall_handle(int32_t x, int32_t y) //Return the highest-layer active pit combo handle at the given position
2240 {
2241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if(int32_t c = MAPFFCOMBO(x,y))
2242 {
2243 return ispitfall(c) ? getFFCAt(x,y) : nullopt;
2244 }
2245 51 int32_t c = MAPCOMBOL(2,x,y);
2246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 2);
2247
2248
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 45 times.
51 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2249 {
2250
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1))
2251 return nullopt;
2252 6 }
2253 else
2254 {
2255
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
45 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1))
2256 return nullopt;
2257 }
2258 51 c = MAPCOMBOL(1,x,y);
2259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 1);
2260
2261
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 45 times.
51 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2262 {
2263
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0))
2264 return nullopt;
2265 6 }
2266 else
2267 {
2268
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
45 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0))
2269 return nullopt;
2270 }
2271 51 c = MAPCOMBO(x,y);
2272
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 0);
2273 return nullopt;
2274 51 }
2275 5458350 bool check_icy(newcombo const& cmb, int type)
2276 {
2277
2/2
✓ Branch 0 taken 5458185 times.
✓ Branch 1 taken 165 times.
5458350 if(cmb.type != cICY)
2278 5458185 return false;
2279
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 165 times.
165 switch(type)
2280 {
2281 case ICY_BLOCK:
2282 return cmb.usrflags&cflag1;
2283 case ICY_PLAYER:
2284 165 return cmb.usrflags&cflag2;
2285 }
2286 return false;
2287 5458350 }
2288 1821974 int get_icy(int x, int y, int type)
2289 {
2290 1821974 int32_t c = MAPCOMBOL(2,x,y);
2291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1821974 times.
1821974 if(check_icy(combobuf[c], type)) return c;
2292
2293 1821974 int screen = get_screen_for_world_xy(x, y);
2294
2295 1821974 mapscr* scr = get_scr_layer_valid(screen, 2);
2296
2/2
✓ Branch 0 taken 4618 times.
✓ Branch 1 taken 1817356 times.
1821974 if (scr)
2297 {
2298
2/2
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 1816840 times.
1817356 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2299 {
2300
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 516 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
516 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1, scr)) return 0;
2301 516 }
2302 else
2303 {
2304
3/4
✓ Branch 0 taken 3048 times.
✓ Branch 1 taken 1813792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3048 times.
1816840 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1, scr)) return 0;
2305 }
2306 1814308 }
2307 1818926 c = MAPCOMBOL(1,x,y);
2308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1818926 times.
1818926 if(check_icy(combobuf[c], type)) return c;
2309
2310 1818926 scr = get_scr_layer_valid(screen, 1);
2311
2/2
✓ Branch 0 taken 12997 times.
✓ Branch 1 taken 1805929 times.
1818926 if (scr)
2312 {
2313
2/2
✓ Branch 0 taken 1934 times.
✓ Branch 1 taken 1803995 times.
1805929 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2314 {
2315
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1934 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1934 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1, scr)) return 0;
2316 1934 }
2317 else
2318 {
2319
3/4
✓ Branch 0 taken 1641 times.
✓ Branch 1 taken 1802354 times.
✓ Branch 2 taken 1641 times.
✗ Branch 3 not taken.
1803995 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1, scr)) return 0;
2320 }
2321 1804288 }
2322 1817285 c = MAPCOMBO(x,y);
2323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1817285 times.
1817285 if(check_icy(combobuf[c], type)) return c;
2324 1817285 return 0;
2325 1821974 }
2326
2327 13059740 static bool checkSV(int32_t x, int32_t y, int32_t flag)
2328 {
2329
8/8
✓ Branch 0 taken 13052942 times.
✓ Branch 1 taken 6798 times.
✓ Branch 2 taken 13044076 times.
✓ Branch 3 taken 8866 times.
✓ Branch 4 taken 13032444 times.
✓ Branch 5 taken 11632 times.
✓ Branch 6 taken 428468 times.
✓ Branch 7 taken 12603976 times.
13059740 if(x<0 || x>=world_w || y<0 || y>=world_h)
2330 455764 return false;
2331
2332 12603976 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, 0);
2333
2/4
✓ Branch 0 taken 12603976 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12603976 times.
12603976 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2334 return true;
2335
2336 12603976 change_rpos_handle_layer(rpos_handle, 1);
2337
2/2
✓ Branch 0 taken 7561110 times.
✓ Branch 1 taken 5042866 times.
12603976 if (rpos_handle.scr->is_valid())
2338
3/4
✓ Branch 0 taken 5042866 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3279 times.
✓ Branch 3 taken 5039587 times.
5042866 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2339 3279 return true;
2340
2341 12600697 change_rpos_handle_layer(rpos_handle, 2);
2342
2/2
✓ Branch 0 taken 10841856 times.
✓ Branch 1 taken 1758841 times.
12600697 if (rpos_handle.scr->is_valid())
2343
2/4
✓ Branch 0 taken 1758841 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1758841 times.
1758841 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2344 return true;
2345
2346 12600697 return false;
2347 13059740 }
2348
2349 6594032 bool isSVLadder(int32_t x, int32_t y)
2350 {
2351 6594032 return checkSV(x, y, mfSIDEVIEWLADDER);
2352 }
2353
2354 6465708 bool isSVPlatform(int32_t x, int32_t y)
2355 {
2356 6465708 return checkSV(x, y, mfSIDEVIEWPLATFORM);
2357 }
2358
2359 6465708 bool checkSVLadderPlatform(int32_t x, int32_t y)
2360 {
2361
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6465708 times.
✓ Branch 2 taken 6463911 times.
✓ Branch 3 taken 1797 times.
6465708 return isSVPlatform(x,y) || (isSVLadder(x,y) && !isSVLadder(x,y-16));
2362 }
2363
2364 1637 bool isstepable(int32_t combo) //can use ladder on it
2365 {
2366
2/2
✓ Branch 0 taken 1631 times.
✓ Branch 1 taken 6 times.
1637 if(combo_class_buf[combobuf[combo].type].ladder_pass) return true;
2367
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(combo_class_buf[combobuf[combo].type].pit)
2368 {
2369 if(combobuf[combo].usrflags&cflag4)
2370 {
2371 int32_t ldrid = current_item_id(itype_ladder);
2372 return (ldrid > -1 && itemsbuf[ldrid].flags & item_flag1);
2373 }
2374 }
2375 6 return false;
2376 1637 }
2377
2378 32780 bool isHSGrabbable(newcombo const& cmb)
2379 {
2380
2/2
✓ Branch 0 taken 373 times.
✓ Branch 1 taken 32407 times.
32780 if(cmb.type == cHSGRAB) return true;
2381 32407 return cmb.genflags & cflag1;
2382 32780 }
2383
2384 954 bool isSwitchHookable(newcombo const& cmb)
2385 {
2386
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 822 times.
954 if(cmb.type == cSWITCHHOOK) return true;
2387 822 return cmb.genflags & cflag2;
2388 954 }
2389
2390 61401 bool check_hshot(int32_t layer, int32_t x, int32_t y, bool switchhook, rpos_t *out_rpos, ffcdata **out_ffc)
2391 {
2392 61401 rpos_t cpos = rpos_t::None;
2393
2/2
✓ Branch 0 taken 64592 times.
✓ Branch 1 taken 125993 times.
61401 if(out_rpos)
2394 {
2395 125993 int32_t id = MAPCOMBO2(layer-1,x,y);
2396
2/2
✓ Branch 0 taken 28634 times.
✓ Branch 1 taken 97359 times.
125993 if(id > 0)
2397 {
2398 97359 newcombo const& cmb = combobuf[id];
2399
4/4
✓ Branch 0 taken 32738 times.
✓ Branch 1 taken 64621 times.
✓ Branch 2 taken 32296 times.
✓ Branch 3 taken 32325 times.
97359 cpos = (switchhook ? isSwitchHookable(cmb) : isHSGrabbable(cmb)) ? COMBOPOS_REGION(x,y) : rpos_t::None;
2400 32767 }
2401 61401 }
2402
2403 125993 ffcdata* ffc = nullptr;
2404
4/4
✓ Branch 0 taken 28389 times.
✓ Branch 1 taken 97604 times.
✓ Branch 2 taken 24996 times.
✓ Branch 3 taken 3393 times.
125993 if (out_ffc && !get_qr(qr_OLD_FFC_FUNCTIONALITY))
2405 {
2406 10359 for_some_ffcs([&](const ffc_handle_t& ffc_handle) {
2407
2/2
✓ Branch 0 taken 6853 times.
✓ Branch 1 taken 113 times.
6966 if (ffcIsAt(ffc_handle, x, y))
2408 {
2409 113 auto& cmb = ffc_handle.combo();
2410
4/4
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 71 times.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 36 times.
113 if (switchhook ? isSwitchHookable(cmb) : isHSGrabbable(cmb))
2411 {
2412 77 ffc = ffc_handle.ffc;
2413 77 return false;
2414 }
2415 36 }
2416 6889 return true;
2417 6896 });
2418 3393 }
2419
2420
4/4
✓ Branch 0 taken 61401 times.
✓ Branch 1 taken 64592 times.
✓ Branch 2 taken 442 times.
✓ Branch 3 taken 60959 times.
125993 if (out_rpos && cpos != rpos_t::None) *out_rpos = cpos;
2421
4/4
✓ Branch 0 taken 28389 times.
✓ Branch 1 taken 97604 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 28382 times.
125993 if (out_ffc && ffc) *out_ffc = ffc;
2422
2/2
✓ Branch 0 taken 65034 times.
✓ Branch 1 taken 60959 times.
125993 return (cpos != rpos_t::None || ffc);
2423 }
2424
2425 5195 bool ishookshottable(int32_t bx, int32_t by)
2426 {
2427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5195 times.
5195 if(!_walkflag(bx,by,1))
2428 return true;
2429
2430
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5187 times.
5195 if (collide_object(bx, by, 1, 1))
2431 8 return false;
2432
2433 5187 bool ret = true;
2434
2/2
✓ Branch 0 taken 15561 times.
✓ Branch 1 taken 1900 times.
17461 for(int32_t i=2; i>=0; i--)
2435 {
2436 15561 int32_t c = MAPCOMBO2(i-1,bx,by);
2437 15561 int32_t t = combobuf[c].type;
2438
2439
6/6
✓ Branch 0 taken 5187 times.
✓ Branch 1 taken 10374 times.
✓ Branch 2 taken 3853 times.
✓ Branch 3 taken 1334 times.
✓ Branch 4 taken 1900 times.
✓ Branch 5 taken 1953 times.
15561 if(i == 0 && (t == cHOOKSHOTONLY || t == cLADDERHOOKSHOT)) return true;
2440
2441
3/4
✓ Branch 0 taken 11321 times.
✓ Branch 1 taken 953 times.
✓ Branch 2 taken 953 times.
✗ Branch 3 not taken.
13227 bool dried = (iswater_type(t) && DRIEDLAKE);
2442
2443 12274 int32_t b=1;
2444
2445
2/2
✓ Branch 0 taken 6109 times.
✓ Branch 1 taken 6165 times.
12274 if(bx&8) b<<=2;
2446
2447
2/2
✓ Branch 0 taken 3841 times.
✓ Branch 1 taken 8433 times.
12274 if(by&8) b<<=1;
2448
2449
7/8
✓ Branch 0 taken 2094 times.
✓ Branch 1 taken 10180 times.
✓ Branch 2 taken 2094 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1115 times.
✓ Branch 5 taken 979 times.
✓ Branch 6 taken 75 times.
✓ Branch 7 taken 904 times.
12274 if(combobuf[c].walk&b && !dried && !(combo_class_buf[t].ladder_pass && t!=cLADDERONLY) && t!=cHOOKSHOTONLY)
2450 904 ret = false;
2451 12274 }
2452
2453 1900 return ret;
2454 5195 }
2455
2456 10110 bool reveal_hidden_stairs(mapscr *s, int32_t screen, bool redraw)
2457 {
2458
4/4
✓ Branch 0 taken 9531 times.
✓ Branch 1 taken 579 times.
✓ Branch 2 taken 9531 times.
✓ Branch 3 taken 579 times.
10110 if((s->stairx || s->stairy) && s->secretcombo[sSTAIRS])
2459 {
2460 579 int pos = COMBOPOS(s->stairx,s->stairy);
2461 579 s->data[pos] = s->secretcombo[sSTAIRS];
2462 579 s->cset[pos] = s->secretcset[sSTAIRS];
2463 579 s->sflag[pos] = s->secretflag[sSTAIRS];
2464
2465
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 323 times.
579 if (redraw)
2466 {
2467 768 auto [x, y] = translate_screen_coordinates_to_world(screen, s->stairx, s->stairy);
2468 768 putcombo(scrollbuf,x,y,s->data[pos],s->cset[pos]);
2469 256 }
2470
2471 579 return true;
2472 }
2473
2474 9531 return false;
2475 10110 }
2476
2477 51233 screen_handles_t create_screen_handles_one(mapscr* base_scr)
2478 {
2479 DCHECK(base_scr->is_valid());
2480
2481 51233 screen_handles_t screen_handles{};
2482 51233 screen_handles[0] = {base_scr, base_scr, base_scr->screen, 0};
2483 51233 return screen_handles;
2484 }
2485
2486 56558231 screen_handles_t create_screen_handles(mapscr* base_scr)
2487 {
2488 DCHECK(get_scr(base_scr->screen) == base_scr);
2489 DCHECK(base_scr->is_valid());
2490
2491 56558231 int screen = base_scr->screen;
2492 screen_handles_t screen_handles;
2493 56558231 screen_handles[0] = {base_scr, base_scr, screen, 0};
2494
2/2
✓ Branch 0 taken 339349386 times.
✓ Branch 1 taken 56558231 times.
395907617 for (int i = 1; i <= 6; i++)
2495 339349386 screen_handles[i] = {base_scr, get_scr_layer_valid(screen, i), screen, i};
2496 56558231 return screen_handles;
2497 }
2498
2499 106202 bool remove_screenstatecombos2(const screen_handles_t& screen_handles, bool do_layers, int32_t what1, int32_t what2)
2500 {
2501 106202 mapscr* scr = screen_handles[0].scr;
2502 106202 bool didit=false;
2503
2504
2/2
✓ Branch 0 taken 106202 times.
✓ Branch 1 taken 18691552 times.
18797754 for(int32_t i=0; i<176; i++)
2505 {
2506 18691552 newcombo const& cmb = combobuf[scr->data[i]];
2507
2/2
✓ Branch 0 taken 326 times.
✓ Branch 1 taken 18691226 times.
18691552 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2508
4/4
✓ Branch 0 taken 18689693 times.
✓ Branch 1 taken 1533 times.
✓ Branch 2 taken 1102 times.
✓ Branch 3 taken 18688591 times.
18691226 if((cmb.type == what1) || (cmb.type== what2))
2509 {
2510 2635 scr->data[i]++;
2511 2635 didit=true;
2512 2635 }
2513 18691226 }
2514
2515
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 106110 times.
106202 if (do_layers)
2516 {
2517
2/2
✓ Branch 0 taken 636660 times.
✓ Branch 1 taken 106110 times.
742770 for(int32_t j=1; j<=6; j++)
2518 {
2519 636660 mapscr* layer_scr = screen_handles[j].scr;
2520
2/2
✓ Branch 0 taken 173130 times.
✓ Branch 1 taken 463530 times.
636660 if (!layer_scr) continue;
2521
2522
2/2
✓ Branch 0 taken 30470880 times.
✓ Branch 1 taken 173130 times.
30644010 for(int32_t i=0; i<176; i++)
2523 {
2524 30470880 newcombo const& cmb = combobuf[layer_scr->data[i]];
2525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30470880 times.
30470880 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2526
4/4
✓ Branch 0 taken 30470797 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 265 times.
✓ Branch 3 taken 30470532 times.
30470880 if((cmb.type== what1) || (cmb.type== what2))
2527 {
2528 348 layer_scr->data[i]++;
2529 348 didit=true;
2530 348 }
2531 30470880 }
2532 173130 }
2533 106110 }
2534
2535 // 'do_layers' also means that this is called on an active temp screen, so update its ffcs.
2536
3/4
✓ Branch 0 taken 20406 times.
✓ Branch 1 taken 85796 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20406 times.
106202 if (!get_qr(qr_OLD_FFC_FUNCTIONALITY) && do_layers)
2537 {
2538 20406 word c = scr->numFFC();
2539
2/2
✓ Branch 0 taken 73350 times.
✓ Branch 1 taken 20406 times.
93756 for(word i=0; i<c; i++)
2540 {
2541 73350 ffcdata* ffc = &scr->ffcs[i];
2542 73350 newcombo const& cmb = combobuf[ffc->data];
2543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73350 times.
73350 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2544
2/4
✓ Branch 0 taken 73350 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73350 times.
73350 if((cmb.type== what1) || (cmb.type== what2))
2545 {
2546 zc_ffc_modify(*ffc, 1);
2547 didit=true;
2548 }
2549 73350 }
2550 20406 }
2551
2552 106202 return didit;
2553 }
2554
2555 14 bool remove_xstatecombos(const screen_handles_t& screen_handles, byte xflag, bool triggers)
2556 {
2557 14 int screen = screen_handles[0].scr->screen;
2558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2559 14 return remove_xstatecombos_mi(screen_handles, mi, xflag, triggers);
2560 }
2561 471650318 bool remove_xstatecombos_mi(const screen_handles_t& screen_handles, int32_t mi, byte xflag, bool triggers)
2562 {
2563 471650318 bool didit=false;
2564
2/2
✓ Branch 0 taken 471619889 times.
✓ Branch 1 taken 30429 times.
471650318 if(!getxmapflag_mi(mi, 1<<xflag)) return false;
2565
2566 30429 mapscr* s = screen_handles[0].scr;
2567 30429 int screen = s->screen;
2568 30429 bool is_active_screen = is_in_current_region(s);
2569
2570 25977933 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
2571
4/4
✓ Branch 0 taken 11264 times.
✓ Branch 1 taken 25936240 times.
✓ Branch 2 taken 1808 times.
✓ Branch 3 taken 25945696 times.
25947504 if(triggers && force_ex_trigger_any(rpos_handle, xflag))
2572 1808 didit = true;
2573
2/2
✓ Branch 0 taken 63627 times.
✓ Branch 1 taken 25882069 times.
25945696 else switch (rpos_handle.ctype())
2574 {
2575 case cLOCKBLOCK: case cLOCKBLOCK2:
2576 case cBOSSLOCKBLOCK: case cBOSSLOCKBLOCK2:
2577 case cCHEST: case cCHEST2:
2578 case cLOCKEDCHEST: case cLOCKEDCHEST2:
2579 case cBOSSCHEST: case cBOSSCHEST2:
2580 {
2581 63627 auto& cmb = rpos_handle.combo();
2582
2/2
✓ Branch 0 taken 62059 times.
✓ Branch 1 taken 1568 times.
63627 if(!(cmb.usrflags&cflag16)) return; //custom state instead of normal state
2583
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 62030 times.
62059 if(cmb.attribytes[5] == xflag)
2584 {
2585 29 rpos_handle.increment_data();
2586 29 didit=true;
2587 29 }
2588 62059 break;
2589 }
2590 }
2591 25947504 });
2592
2593
4/4
✓ Branch 0 taken 30388 times.
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 20768 times.
✓ Branch 3 taken 9620 times.
30429 if (is_active_screen && !get_qr(qr_OLD_FFC_FUNCTIONALITY))
2594 {
2595 20768 word c = s->numFFC();
2596 20768 int screen_index_offset = get_region_screen_offset(screen);
2597
2/2
✓ Branch 0 taken 36840 times.
✓ Branch 1 taken 20768 times.
57608 for (uint8_t i = 0; i < c; i++)
2598 {
2599 36840 auto ffc_handle = *s->getFFCHandle(i, screen_index_offset);
2600 36840 auto& cmb = ffc_handle.combo();
2601
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 36840 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 36824 times.
36840 if(triggers && force_ex_trigger_any(ffc_handle, xflag))
2602 16 didit = true;
2603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36824 times.
36824 else switch(cmb.type)
2604 {
2605 case cLOCKBLOCK: case cLOCKBLOCK2:
2606 case cBOSSLOCKBLOCK: case cBOSSLOCKBLOCK2:
2607 case cCHEST: case cCHEST2:
2608 case cLOCKEDCHEST: case cLOCKEDCHEST2:
2609 case cBOSSCHEST: case cBOSSCHEST2:
2610 {
2611 if(!(cmb.usrflags&cflag16)) continue; //custom state instead of normal state
2612 if(cmb.attribytes[5] == xflag)
2613 {
2614 zc_ffc_modify(*ffc_handle.ffc, 1);
2615 didit=true;
2616 }
2617 break;
2618 }
2619 }
2620 36840 }
2621 20768 }
2622
2623 30429 return didit;
2624 471650318 }
2625
2626 14687616 void clear_xstatecombos(const screen_handles_t& screen_handles, bool triggers)
2627 {
2628 14687616 int screen = screen_handles[0].screen;
2629
2/2
✓ Branch 0 taken 387833 times.
✓ Branch 1 taken 14299783 times.
14687616 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2630 14687616 clear_xstatecombos_mi(screen_handles, mi, triggers);
2631 14687616 }
2632
2633 14739072 void clear_xstatecombos_mi(const screen_handles_t& screen_handles, int32_t mi, bool triggers)
2634 {
2635
2/2
✓ Branch 0 taken 471650304 times.
✓ Branch 1 taken 14739072 times.
486389376 for (int q = 0; q < 32; ++q)
2636 {
2637 471650304 remove_xstatecombos_mi(screen_handles, mi, q, triggers);
2638 471650304 }
2639 14739072 }
2640
2641 bool remove_xdoors(const screen_handles_t& screen_handles, uint dir, uint ind, bool triggers)
2642 {
2643 int screen = screen_handles[0].screen;
2644 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2645 return remove_xdoors_mi(screen_handles, mi, dir, ind, triggers);
2646 }
2647 471650304 bool remove_xdoors_mi(const screen_handles_t& screen_handles, int32_t mi, uint dir, uint ind, bool triggers)
2648 {
2649 471650304 bool didit=false;
2650
2/2
✓ Branch 0 taken 471648991 times.
✓ Branch 1 taken 1313 times.
471650304 if (!getxdoor_mi(mi, dir, ind)) return false;
2651
2652 1313 mapscr* scr = screen_handles[0].scr;
2653 1313 int screen = scr->screen;
2654 1313 bool is_active_screen = is_in_current_region(scr);
2655
2656 925665 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
2657
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 924352 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 924341 times.
924352 if (triggers && force_ex_door_trigger_any(rpos_handle, dir, ind))
2658 11 didit = true;
2659 else; //future door combo types?
2660 924352 });
2661
2662
2/4
✓ Branch 0 taken 1313 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1313 times.
✗ Branch 3 not taken.
1313 if (!get_qr(qr_OLD_FFC_FUNCTIONALITY) && is_active_screen)
2663 {
2664 1313 word c = scr->numFFC();
2665 1313 int screen_index_offset = get_region_screen_offset(screen);
2666
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1313 times.
1313 for (uint8_t i = 0; i < c; i++)
2667 {
2668 auto ffc_handle = *scr->getFFCHandle(i, screen_index_offset);
2669 if (triggers && force_ex_door_trigger_any(ffc_handle, dir, ind))
2670 didit = true;
2671 else; //future door combo types?
2672 }
2673 1313 }
2674
2675 1313 return didit;
2676 471650304 }
2677
2678 14687616 void clear_xdoors(const screen_handles_t& screen_handles, bool triggers)
2679 {
2680 14687616 int screen = screen_handles[0].screen;
2681
2/2
✓ Branch 0 taken 387833 times.
✓ Branch 1 taken 14299783 times.
14687616 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2682 14687616 return clear_xdoors_mi(screen_handles, mi, triggers);
2683 }
2684
2685 14739072 void clear_xdoors_mi(const screen_handles_t& screen_handles, int32_t mi, bool triggers)
2686 {
2687
2/2
✓ Branch 0 taken 58956288 times.
✓ Branch 1 taken 14739072 times.
73695360 for (int dir = 0; dir < 4; ++dir)
2688
2/2
✓ Branch 0 taken 471650304 times.
✓ Branch 1 taken 58956288 times.
530606592 for (int q = 0; q < 8; ++q)
2689 530606592 remove_xdoors_mi(screen_handles, mi, dir, q, triggers);
2690 14739072 }
2691
2692 763 bool remove_lockblocks(const screen_handles_t& screen_handles)
2693 {
2694 763 return remove_screenstatecombos2(screen_handles, true, cLOCKBLOCK, cLOCKBLOCK2);
2695 }
2696
2697 98 bool remove_bosslockblocks(const screen_handles_t& screen_handles)
2698 {
2699 98 return remove_screenstatecombos2(screen_handles, true, cBOSSLOCKBLOCK, cBOSSLOCKBLOCK2);
2700 }
2701
2702 76553 bool remove_chests(const screen_handles_t& screen_handles)
2703 {
2704 76553 return remove_screenstatecombos2(screen_handles, true, cCHEST, cCHEST2);
2705 }
2706
2707 2484 bool remove_lockedchests(const screen_handles_t& screen_handles)
2708 {
2709 2484 return remove_screenstatecombos2(screen_handles, true, cLOCKEDCHEST, cLOCKEDCHEST2);
2710 }
2711
2712 26212 bool remove_bosschests(const screen_handles_t& screen_handles)
2713 {
2714 26212 return remove_screenstatecombos2(screen_handles, true, cBOSSCHEST, cBOSSCHEST2);
2715 }
2716
2717 1385105 void delete_fireball_shooter(const rpos_handle_t& rpos_handle)
2718 {
2719 1385105 int32_t ct=rpos_handle.ctype();
2720
2721
6/6
✓ Branch 0 taken 1384485 times.
✓ Branch 1 taken 620 times.
✓ Branch 2 taken 1384233 times.
✓ Branch 3 taken 252 times.
✓ Branch 4 taken 1384125 times.
✓ Branch 5 taken 108 times.
1385105 if(ct!=cL_STATUE && ct!=cR_STATUE && ct!=cC_STATUE)
2722 1384125 return;
2723
2724 2465 auto [cx, cy] = rpos_handle.xy();
2725
3/4
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 620 times.
✓ Branch 3 taken 108 times.
980 switch(ct)
2726 {
2727 case cL_STATUE:
2728 620 cx += 4;
2729 620 cy += 7;
2730 620 break;
2731
2732 case cR_STATUE:
2733 252 cx -= 8;
2734 252 cy -= 1;
2735 252 break;
2736
2737 case cC_STATUE:
2738 108 break;
2739 }
2740
2741
2/2
✓ Branch 0 taken 980 times.
✓ Branch 1 taken 1485 times.
2465 for(int32_t j=0; j<guys.Count(); j++)
2742 {
2743 // Finds the smallest enemy ID
2744
9/10
✓ Branch 0 taken 399 times.
✓ Branch 1 taken 1086 times.
✓ Branch 2 taken 399 times.
✓ Branch 3 taken 1086 times.
✓ Branch 4 taken 346 times.
✓ Branch 5 taken 53 times.
✓ Branch 6 taken 346 times.
✓ Branch 7 taken 53 times.
✓ Branch 8 taken 346 times.
✗ Branch 9 not taken.
2970 if((int32_t(guys.spr(j)->x)==cx)&&(int32_t(guys.spr(j)->y)==cy)&&(guysbuf[(guys.spr(j)->id)&0xFFF].flags & guy_fire))
2745 {
2746 346 guys.del(j);
2747 346 }
2748 1485 }
2749 1385105 }
2750
2751 15 static int32_t findtrigger(int32_t screen)
2752 {
2753 15 int32_t checkflag=0;
2754 15 int32_t ret = 0;
2755
2756 mapscr* screens[7];
2757
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 15 times.
120 for (int32_t j = 0; j <= 6; j++)
2758 {
2759 105 screens[j] = get_scr_layer_valid(screen, j);
2760 105 }
2761
2762 15 bool sflag = false;
2763
2/2
✓ Branch 0 taken 2640 times.
✓ Branch 1 taken 15 times.
2655 for(word j=0; j<176; j++)
2764 {
2765
2/2
✓ Branch 0 taken 26752 times.
✓ Branch 1 taken 2640 times.
29392 for(int32_t layer = -1; layer < 6; ++layer)
2766 {
2767 26752 mapscr* scr = screens[layer+1];
2768
2/2
✓ Branch 0 taken 16544 times.
✓ Branch 1 taken 10208 times.
26752 if (!scr) continue;
2769
2770
2/2
✓ Branch 0 taken 8272 times.
✓ Branch 1 taken 8272 times.
16544 if(sflag)
2771 8272 checkflag = scr->sflag[j];
2772 else
2773 8272 checkflag = combobuf[scr->data[j]].flag;
2774 16544 sflag = !sflag;
2775
2/2
✓ Branch 0 taken 8272 times.
✓ Branch 1 taken 8272 times.
16544 if (sflag) --layer;
2776
2777
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 16534 times.
16544 switch(checkflag)
2778 {
2779 case mfANYFIRE:
2780 case mfSTRONGFIRE:
2781 case mfMAGICFIRE:
2782 case mfDIVINEFIRE:
2783 case mfARROW:
2784 case mfSARROW:
2785 case mfGARROW:
2786 case mfSBOMB:
2787 case mfBOMB:
2788 case mfBRANG:
2789 case mfMBRANG:
2790 case mfFBRANG:
2791 case mfWANDMAGIC:
2792 case mfREFMAGIC:
2793 case mfREFFIREBALL:
2794 case mfSWORD:
2795 case mfWSWORD:
2796 case mfMSWORD:
2797 case mfXSWORD:
2798 case mfSWORDBEAM:
2799 case mfWSWORDBEAM:
2800 case mfMSWORDBEAM:
2801 case mfXSWORDBEAM:
2802 case mfHOOKSHOT:
2803 case mfWAND:
2804 case mfHAMMER:
2805 case mfSTRIKE:
2806 10 ret += 1;
2807 10 break;
2808 }
2809 16544 }
2810 2640 }
2811
2812 15 return ret;
2813 }
2814
2815 11738 static void log_trigger_secret_reason(TriggerSource source)
2816 {
2817
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11299 times.
11738 if (source == TriggerSource::Singular)
2818 {
2819 439 Z_eventlog("Restricted Screen Secrets triggered\n");
2820 439 }
2821 else
2822 {
2823 11299 const char* source_str = "";
2824
7/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 7178 times.
✓ Branch 3 taken 856 times.
✓ Branch 4 taken 2733 times.
✓ Branch 5 taken 475 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 52 times.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
11299 switch (source)
2825 {
2826 case TriggerSource::Singular: break;
2827 7178 case TriggerSource::Unspecified: source_str = "unspecified means"; break;
2828 856 case TriggerSource::EnemiesScreenFlag: source_str = "the 'Enemies->Secret' screen flag"; break;
2829 2733 case TriggerSource::SecretsScreenState: source_str = "the 'Secrets' screen state"; break;
2830 475 case TriggerSource::Script: source_str = "a script"; break;
2831 1 case TriggerSource::ItemsSecret: source_str = "Items->Secrets"; break;
2832 52 case TriggerSource::GenericCombo: source_str = "Generic Combo"; break;
2833 4 case TriggerSource::LightTrigger: source_str = "Light Triggers"; break;
2834 case TriggerSource::SCC: source_str = "SCC"; break;
2835 case TriggerSource::CheatTemp: source_str = "Cheat (Temp)"; break;
2836 case TriggerSource::CheatPerm: source_str = "Cheat (Perm)"; break;
2837 }
2838 11299 Z_eventlog("Screen Secrets triggered by %s\n", source_str);
2839 }
2840 11738 }
2841
2842 // single:
2843 // >-1 : the singular triggering combo
2844 // -1: triggered by some other cause
2845 11530 void trigger_secrets_for_screen(TriggerSource source, mapscr* scr, bool high16only, int32_t single)
2846 {
2847 11530 log_trigger_secret_reason(source);
2848
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11091 times.
11530 if (single < 0)
2849 11091 get_screen_state(scr->screen).triggered_secrets = true;
2850
2851 11530 bool do_replay_comment = true;
2852 11530 bool from_active_screen = true;
2853 11530 trigger_secrets_for_screen_internal(create_screen_handles(scr), from_active_screen, high16only, single, do_replay_comment);
2854
2855 // Respect secret state carryovers for active screens.
2856
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11091 times.
11530 if (single >= 0) return;
2857
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 11068 times.
11091 if(scr->nocarry&mSECRET) return;
2858 11068 int cmap = scr->map;
2859 11068 int cscr = scr->screen;
2860 11068 int nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
2861 11068 int nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
2862
2863 11068 std::vector<int32_t> done;
2864
2/2
✓ Branch 0 taken 10896 times.
✓ Branch 1 taken 172 times.
11068 bool looped = (nmap==cmap+1 && nscr==cscr);
2865
2866
6/6
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 11001 times.
✓ Branch 2 taken 67 times.
✓ Branch 3 taken 417 times.
✓ Branch 4 taken 417 times.
✓ Branch 5 taken 11068 times.
11485 while((nmap!=0) && !looped && !(nscr>=128))
2867 {
2868
7/8
✓ Branch 0 taken 317 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 74 times.
✓ Branch 3 taken 243 times.
✓ Branch 4 taken 74 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 70 times.
417 if (nmap - 1 == cur_map && is_in_current_region(nscr) && !get_screen_state(nscr).triggered_secrets)
2869 {
2870
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 log_trigger_secret_reason(TriggerSource::SecretsScreenState);
2871
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 trigger_secrets_for_screen_internal(create_screen_handles(get_scr(nscr)), from_active_screen, high16only, single, do_replay_comment);
2872
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 get_screen_state(nscr).triggered_secrets = true;
2873 4 }
2874
2875 417 cmap=nmap;
2876 417 cscr=nscr;
2877 417 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
2878 417 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
2879
2880
2/2
✓ Branch 0 taken 386 times.
✓ Branch 1 taken 417 times.
803 for(auto it = done.begin(); it != done.end(); it++)
2881 {
2882
2/2
✓ Branch 0 taken 319 times.
✓ Branch 1 taken 67 times.
386 if(*it == ((nmap-1)<<7)+nscr)
2883 67 looped = true;
2884 386 }
2885
2886
1/2
✓ Branch 0 taken 417 times.
✗ Branch 1 not taken.
417 done.push_back(((nmap-1)<<7)+nscr);
2887 }
2888 11530 }
2889
2890 2437 void trigger_secrets_for_screen(TriggerSource source, int32_t screen, bool high16only, int32_t single)
2891 {
2892 2437 trigger_secrets_for_screen(source, get_scr(screen), high16only, single);
2893 2437 }
2894
2895 18007 void trigger_secrets_for_screen_internal(const screen_handles_t& screen_handles, bool from_active_screen, bool high16only, int32_t single, bool do_replay_comment)
2896 {
2897 18007 mapscr* scr = screen_handles[0].scr;
2898 18007 int screen = scr->screen;
2899
2900 // TODO(replays): No real reason for "do_replay_comment" to exist - I just did not want to update many replays when fixing
2901 // slopes in sideview mode (which required loading nearby screens in loadscr).
2902 // TODO(replays): This should just use `screen`.
2903
3/4
✓ Branch 0 taken 18007 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 539 times.
✓ Branch 3 taken 17468 times.
18007 if (replay_is_active() && do_replay_comment)
2904
4/6
✓ Branch 0 taken 11534 times.
✓ Branch 1 taken 5934 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11534 times.
✓ Branch 4 taken 17468 times.
✗ Branch 5 not taken.
17468 replay_step_comment(fmt::format("trigger secrets scr={}", from_active_screen && scr != special_warp_return_scr ? screen : cur_screen));
2905
2906
2/2
✓ Branch 0 taken 6473 times.
✓ Branch 1 taken 11534 times.
18007 if (from_active_screen)
2907 {
2908 5529590 for_every_combo_in_screen(screen_handles, [&](const auto& handle) {
2909
2/4
✓ Branch 0 taken 5516368 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1688 times.
✗ Branch 3 not taken.
5834885 trig_each_combo_trigger(handle, [&](combo_trigger const& trig){
2910 316829 return trig.trigger_flags.get(TRIGFLAG_SECRETSTR);
2911 }, ctrigSECRETS);
2912 5518056 });
2913 11534 }
2914
2915 18007 int32_t ft=0; //Flag trigger?
2916 18007 int32_t msflag=0; // Misc. secret flag
2917
2918
2/2
✓ Branch 0 taken 3169232 times.
✓ Branch 1 taken 18007 times.
3187239 for(int32_t i=0; i<176; i++) //Do the 'trigger flags' (non 16-31)
2919 {
2920
4/4
✓ Branch 0 taken 77264 times.
✓ Branch 1 taken 3091968 times.
✓ Branch 2 taken 439 times.
✓ Branch 3 taken 76825 times.
3169232 if(single>=0 && i!=single) continue; //If it's got a singular flag and i isn't where the flag is
2921
2922 // Remember the misc. secret flag; if triggered, use this instead
2923
4/4
✓ Branch 0 taken 114511 times.
✓ Branch 1 taken 2977896 times.
✓ Branch 2 taken 49462 times.
✓ Branch 3 taken 65049 times.
3092407 if(scr->sflag[i]>=mfSECRETS01 && scr->sflag[i]<=mfSECRETS16)
2924 65049 msflag=sSECRET01+(scr->sflag[i]-mfSECRETS01);
2925
4/4
✓ Branch 0 taken 47230 times.
✓ Branch 1 taken 2980128 times.
✓ Branch 2 taken 46999 times.
✓ Branch 3 taken 231 times.
3027358 else if(combobuf[scr->data[i]].flag>=mfSECRETS01 && combobuf[scr->data[i]].flag<=mfSECRETS16)
2926 231 msflag=sSECRET01+(combobuf[scr->data[i]].flag-mfSECRETS01);
2927 else
2928 3027127 msflag=0;
2929
2930
4/4
✓ Branch 0 taken 921256 times.
✓ Branch 1 taken 2171151 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 921184 times.
3092407 if(!high16only || single>=0)
2931 {
2932 2171223 int32_t newflag = -1;
2933
2934
2/2
✓ Branch 0 taken 4342446 times.
✓ Branch 1 taken 2171223 times.
6513669 for(int32_t iter=0; iter<2; ++iter)
2935 {
2936 4342446 int32_t checkflag=combobuf[scr->data[i]].flag; //Inherent
2937
2938
2/2
✓ Branch 0 taken 2171223 times.
✓ Branch 1 taken 2171223 times.
4342446 if(iter==1) checkflag=scr->sflag[i]; //Placed
2939
2940 4342446 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2941
2/2
✓ Branch 0 taken 4330212 times.
✓ Branch 1 taken 12234 times.
4342446 if (ft != -1) //Change the combos for the secret
2942 {
2943 // Use misc. secret flag instead if one is present
2944
2/2
✓ Branch 0 taken 12202 times.
✓ Branch 1 taken 32 times.
12234 if(msflag!=0)
2945 32 ft=msflag;
2946
2947 12234 rpos_handle_t rpos_handle;
2948
2/2
✓ Branch 0 taken 6367 times.
✓ Branch 1 taken 5867 times.
12234 if (from_active_screen)
2949 {
2950 5867 rpos_handle = get_rpos_handle_for_scr(scr, 0, i);
2951 5867 screen_combo_modify_preroutine(rpos_handle);
2952 5867 }
2953
2954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12234 times.
12234 if(ft==sSECNEXT)
2955 {
2956 scr->data[i]++;
2957 }
2958 else
2959 {
2960 12234 scr->data[i] = scr->secretcombo[ft];
2961 12234 scr->cset[i] = scr->secretcset[ft];
2962 }
2963 12234 newflag = scr->secretflag[ft];
2964
2965
2/2
✓ Branch 0 taken 6367 times.
✓ Branch 1 taken 5867 times.
12234 if (from_active_screen)
2966 5867 screen_combo_modify_postroutine(rpos_handle);
2967 12234 }
2968 4342446 }
2969
2970
2/2
✓ Branch 0 taken 2158995 times.
✓ Branch 1 taken 12228 times.
2171223 if(newflag >-1) scr->sflag[i] = newflag; //Tiered secret
2971
2972
2/2
✓ Branch 0 taken 13027338 times.
✓ Branch 1 taken 2171223 times.
15198561 for(int32_t j=1; j<=6; j++) //Layers
2973 {
2974 13027338 mapscr* layer_scr = screen_handles[j].scr;
2975
2/2
✓ Branch 0 taken 3213077 times.
✓ Branch 1 taken 9814261 times.
13027338 if (!layer_scr) continue;
2976
2977
3/4
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 3212352 times.
✓ Branch 2 taken 725 times.
✗ Branch 3 not taken.
3213077 if(single>=0 && i!=single) continue; //If it's got a singular flag and i isn't where the flag is
2978
2979 3213077 int32_t newflag2 = -1;
2980
2981 // Remember the misc. secret flag; if triggered, use this instead
2982
4/4
✓ Branch 0 taken 14182 times.
✓ Branch 1 taken 3198895 times.
✓ Branch 2 taken 4773 times.
✓ Branch 3 taken 9409 times.
3213077 if(layer_scr->sflag[i]>=mfSECRETS01 && layer_scr->sflag[i]<=mfSECRETS16)
2983 9409 msflag=sSECRET01+(layer_scr->sflag[i]-mfSECRETS01);
2984
4/4
✓ Branch 0 taken 126931 times.
✓ Branch 1 taken 3076737 times.
✓ Branch 2 taken 126560 times.
✓ Branch 3 taken 371 times.
3203668 else if(combobuf[layer_scr->data[i]].flag>=mfSECRETS01 && combobuf[layer_scr->data[i]].flag<=mfSECRETS16)
2985 371 msflag=sSECRET01+(combobuf[layer_scr->data[i]].flag-mfSECRETS01);
2986 else
2987 3203297 msflag=0;
2988
2989
2/2
✓ Branch 0 taken 6426154 times.
✓ Branch 1 taken 3213077 times.
9639231 for(int32_t iter=0; iter<2; ++iter)
2990 {
2991 6426154 int32_t checkflag=combobuf[layer_scr->data[i]].flag; //Inherent
2992
2/2
✓ Branch 0 taken 3213077 times.
✓ Branch 1 taken 3213077 times.
6426154 if(iter==1) checkflag=layer_scr->sflag[i]; //Placed
2993
2994 6426154 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2995
2/2
✓ Branch 0 taken 6425676 times.
✓ Branch 1 taken 478 times.
6426154 if (ft != -1) //Change the combos for the secret
2996 {
2997 // Use misc. secret flag instead if one is present
2998
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 2 times.
478 if(msflag!=0)
2999 2 ft=msflag;
3000
3001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 478 times.
478 if(ft==sSECNEXT)
3002 {
3003 layer_scr->data[i]++;
3004 }
3005 else
3006 {
3007 478 layer_scr->data[i] = layer_scr->secretcombo[ft];
3008 478 layer_scr->cset[i] = layer_scr->secretcset[ft];
3009 }
3010 478 newflag2 = layer_scr->secretflag[ft];
3011 478 int32_t c=layer_scr->data[i];
3012 478 int32_t cs=layer_scr->cset[i];
3013
3014
3/4
✓ Branch 0 taken 406 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 406 times.
✗ Branch 3 not taken.
478 if (from_active_screen && combobuf[c].type==cSPINTILE1) //Surely this means we can have spin tiles on layers 3+? Isn't that bad? ~Joe123
3015 {
3016 auto [offx, offy] = translate_screen_coordinates_to_world(screen, COMBOX(i), COMBOY(i));
3017 addenemy(screen,offx,offy,(cs<<12)+eSPINTILE1,combobuf[c].o_tile+zc_max(1,combobuf[c].frames));
3018 }
3019 478 }
3020 6426154 }
3021
3022
2/2
✓ Branch 0 taken 478 times.
✓ Branch 1 taken 3212599 times.
3213077 if(newflag2 >-1) layer_scr->sflag[i] = newflag2; //Tiered secret
3023 3213077 }
3024 2171223 }
3025 3092407 }
3026
3027 18007 word c = scr->numFFC();
3028
2/2
✓ Branch 0 taken 506903 times.
✓ Branch 1 taken 18007 times.
524910 for(word i=0; i<c; i++) //FFC 'trigger flags'
3029 {
3030
3/4
✓ Branch 0 taken 492983 times.
✓ Branch 1 taken 13920 times.
✓ Branch 2 taken 13920 times.
✗ Branch 3 not taken.
506903 if(single>=0) if(i+176!=single) continue;
3031
3032
3/4
✓ Branch 0 taken 166605 times.
✓ Branch 1 taken 326378 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 166605 times.
492983 if((!high16only)||(single>=0))
3033 {
3034 //for (int32_t iter=0; iter<1; ++iter) // Only one kind of FFC flag now.
3035 {
3036 326378 int32_t checkflag=combobuf[scr->ffcs[i].data].flag; //Inherent
3037 //No placed flags yet
3038
3039 326378 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
3040
2/2
✓ Branch 0 taken 326347 times.
✓ Branch 1 taken 31 times.
326378 if (ft != -1) //Change the ffc's combo
3041 {
3042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if(ft==sSECNEXT)
3043 {
3044 zc_ffc_modify(scr->ffcs[i], 1);
3045 }
3046 else
3047 {
3048 31 zc_ffc_set(scr->ffcs[i], scr->secretcombo[ft]);
3049 31 scr->ffcs[i].cset = scr->secretcset[ft];
3050 }
3051 31 }
3052 }
3053 326378 }
3054 492983 }
3055
3056
2/2
✓ Branch 0 taken 15610 times.
✓ Branch 1 taken 2397 times.
18007 if(checktrigger) //Hit all triggers->16-31
3057 {
3058 2397 checktrigger=false;
3059
3060
2/2
✓ Branch 0 taken 2388 times.
✓ Branch 1 taken 9 times.
2397 if(scr->flags6&fTRIGGERF1631)
3061 {
3062 9 int32_t tr = findtrigger(screen); //Normal flags
3063
3064
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
9 if(tr)
3065 {
3066 5 Z_eventlog("Hit All Triggers->16-31 not fulfilled (%d trigger flag%s remain).\n", tr, tr>1?"s":"");
3067 5 goto endhe;
3068 }
3069 4 }
3070 2392 }
3071
3072
2/2
✓ Branch 0 taken 3168352 times.
✓ Branch 1 taken 18002 times.
3186354 for(int32_t i=0; i<176; i++) // Do the 16-31 secrets
3073 {
3074 //If it's an enemies->secret screen, only do the high 16 if told to
3075 //That way you can have secret and burn/bomb entrance separately
3076 3168352 bool old_enem_secret = get_qr(qr_ENEMIES_SECRET_ONLY_16_31);
3077
6/6
✓ Branch 0 taken 2780624 times.
✓ Branch 1 taken 387728 times.
✓ Branch 2 taken 85184 times.
✓ Branch 3 taken 3083168 times.
✓ Branch 4 taken 19536 times.
✓ Branch 5 taken 65648 times.
3168352 if(((!(old_enem_secret && (scr->flags2&fCLEARSECRET)) /*Enemies->Secret*/ && single < 0) || high16only || scr->flags4&fENEMYSCRTPERM))
3078 {
3079 3102704 int32_t newflag = -1;
3080
3081
2/2
✓ Branch 0 taken 6205408 times.
✓ Branch 1 taken 3102704 times.
9308112 for(int32_t iter=0; iter<2; ++iter)
3082 {
3083 6205408 int32_t checkflag=combobuf[scr->data[i]].flag; //Inherent
3084
3085
2/2
✓ Branch 0 taken 3102704 times.
✓ Branch 1 taken 3102704 times.
6205408 if(iter==1) checkflag=scr->sflag[i]; //Placed
3086
3087
4/4
✓ Branch 0 taken 161185 times.
✓ Branch 1 taken 6044223 times.
✓ Branch 2 taken 94853 times.
✓ Branch 3 taken 66332 times.
6205408 if((checkflag > 15)&&(checkflag < 32)) //If we've got a 16->32 flag change the combo
3088 {
3089 66332 rpos_handle_t rpos_handle;
3090
2/2
✓ Branch 0 taken 9952 times.
✓ Branch 1 taken 56380 times.
66332 if (from_active_screen)
3091 {
3092 56380 rpos_handle = get_rpos_handle_for_scr(scr, 0, i);
3093 56380 screen_combo_modify_preroutine(rpos_handle);
3094 56380 }
3095
3096 66332 scr->data[i] = scr->secretcombo[checkflag-16+4];
3097 66332 scr->cset[i] = scr->secretcset[checkflag-16+4];
3098 66332 newflag = scr->secretflag[checkflag-16+4];
3099
3100
2/2
✓ Branch 0 taken 9952 times.
✓ Branch 1 taken 56380 times.
66332 if (from_active_screen)
3101 56380 screen_combo_modify_postroutine(rpos_handle);
3102 66332 }
3103 6205408 }
3104
3105
2/2
✓ Branch 0 taken 3036396 times.
✓ Branch 1 taken 66308 times.
3102704 if(newflag >-1) scr->sflag[i] = newflag; //Tiered flag
3106
3107
2/2
✓ Branch 0 taken 18616224 times.
✓ Branch 1 taken 3102704 times.
21718928 for(int32_t j=1; j<=6; j++) //Layers
3108 {
3109 18616224 mapscr* layer_scr = screen_handles[j].scr;
3110
2/2
✓ Branch 0 taken 4895440 times.
✓ Branch 1 taken 13720784 times.
18616224 if (!layer_scr) continue;
3111
3112 4895440 int32_t newflag2 = -1;
3113
3114
2/2
✓ Branch 0 taken 9790880 times.
✓ Branch 1 taken 4895440 times.
14686320 for(int32_t iter=0; iter<2; ++iter)
3115 {
3116 9790880 int32_t checkflag=combobuf[layer_scr->data[i]].flag; //Inherent
3117
3118
2/2
✓ Branch 0 taken 4895440 times.
✓ Branch 1 taken 4895440 times.
9790880 if(iter==1) checkflag=layer_scr->sflag[i]; //Placed
3119
3120
4/4
✓ Branch 0 taken 151246 times.
✓ Branch 1 taken 9639634 times.
✓ Branch 2 taken 131622 times.
✓ Branch 3 taken 19624 times.
9790880 if((checkflag > 15)&&(checkflag < 32)) //If we've got a 16->32 flag change the combo
3121 {
3122 19624 layer_scr->data[i] = layer_scr->secretcombo[checkflag-16+4];
3123 19624 layer_scr->cset[i] = layer_scr->secretcset[checkflag-16+4];
3124 19624 newflag2 = layer_scr->secretflag[checkflag-16+4];
3125 19624 }
3126 9790880 }
3127
3128
2/2
✓ Branch 0 taken 4875816 times.
✓ Branch 1 taken 19624 times.
4895440 if(newflag2 >-1) layer_scr->sflag[i] = newflag2; //Tiered flag
3129 4895440 }
3130 3102704 }
3131 3168352 }
3132
3133
2/2
✓ Branch 0 taken 506743 times.
✓ Branch 1 taken 18002 times.
524745 for(word i=0; i<c; i++) // FFCs
3134 {
3135
6/6
✓ Branch 0 taken 466852 times.
✓ Branch 1 taken 39891 times.
✓ Branch 2 taken 15367 times.
✓ Branch 3 taken 491376 times.
✓ Branch 4 taken 3530 times.
✓ Branch 5 taken 11837 times.
506743 if((!(scr->flags2&fCLEARSECRET) /*Enemies->Secret*/ && single < 0) || high16only || scr->flags4&fENEMYSCRTPERM)
3136 {
3137 494906 int32_t checkflag=combobuf[scr->ffcs[i].data].flag; //Inherent
3138
3139 //No placed flags yet
3140
4/4
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 494838 times.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 12 times.
494906 if((checkflag > 15)&&(checkflag < 32)) //If we find a flag, change the combo
3141 {
3142
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 if (from_active_screen)
3143 9 zc_ffc_set(scr->ffcs[i], scr->secretcombo[checkflag - 16 + 4]);
3144 else
3145 3 scr->ffcs[i].data = scr->secretcombo[checkflag - 16 + 4];
3146 12 scr->ffcs[i].cset = scr->secretcset[checkflag-16+4];
3147 12 }
3148 494906 }
3149 524745 }
3150
3151 endhe:
3152
3153
1/2
✓ Branch 0 taken 18007 times.
✗ Branch 1 not taken.
18007 if (scr->flags4&fDISABLETIME) //Finish timed warp if 'Secrets Disable Timed Warp'
3154 {
3155 if (from_active_screen)
3156 activated_timed_warp = true;
3157 scr->timedwarptics = 0;
3158 }
3159 18007 }
3160
3161 // x,y are world coordinates.
3162 // Returns true if there is a flag (either combo, screen, or ffc) at (x, y).
3163 // Out parameters will be set if the flag is Trigger->Self, which modifies how secrets will be triggered.
3164 13546841 static bool has_flag_trigger(int32_t x, int32_t y, int32_t flag, rpos_t& out_rpos, bool& out_single16)
3165 {
3166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13546841 times.
13546841 if (!is_in_world_bounds(x, y)) return false;
3167
3168 13546841 bool found_cflag = false;
3169 13546841 bool found_nflag = false;
3170 13546841 bool single16 = false;
3171 13546841 rpos_t rpos = rpos_t::None;
3172
3173
2/2
✓ Branch 0 taken 13544757 times.
✓ Branch 1 taken 94815695 times.
108360452 for (int32_t layer = -1; layer < 6; layer++)
3174 {
3175
2/2
✓ Branch 0 taken 94813611 times.
✓ Branch 1 taken 2084 times.
94815695 if (MAPFLAG2(layer, x, y) == flag)
3176 {
3177 2084 found_nflag = true;
3178 2084 break;
3179 }
3180 94813611 }
3181
3182
2/2
✓ Branch 0 taken 13546537 times.
✓ Branch 1 taken 94826611 times.
108373148 for (int32_t layer = -1; layer < 6; layer++)
3183 {
3184
2/2
✓ Branch 0 taken 94826307 times.
✓ Branch 1 taken 304 times.
94826611 if (MAPCOMBOFLAG2(layer, x, y) == flag)
3185 {
3186 304 found_cflag = true;
3187 304 break;
3188 }
3189 94826307 }
3190
3191
2/2
✓ Branch 0 taken 94827887 times.
✓ Branch 1 taken 13546841 times.
108374728 for (int32_t i=-1; i<6; i++) // Look for Trigger->Self on all layers
3192 {
3193
2/2
✓ Branch 0 taken 94813299 times.
✓ Branch 1 taken 14588 times.
94827887 if (found_nflag) // Trigger->Self (a.k.a Singular) is inherent
3194 {
3195
3/4
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 14476 times.
✓ Branch 2 taken 112 times.
✗ Branch 3 not taken.
14588 if ((MAPCOMBOFLAG2(i, x, y) == mfSINGLE) && (MAPFLAG2(i, x, y) == flag))
3196 {
3197 112 rpos = COMBOPOS_REGION(x, y);
3198 112 }
3199
3/4
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 14424 times.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
14476 else if ((MAPCOMBOFLAG2(i, x, y) == mfSINGLE16) && (MAPFLAG2(i, x, y) == flag))
3200 {
3201 52 rpos = COMBOPOS_REGION(x, y);
3202 52 single16 = true;
3203 52 }
3204 14588 }
3205
3206
2/2
✓ Branch 0 taken 94825759 times.
✓ Branch 1 taken 2128 times.
94827887 if (found_cflag) // Trigger->Self (a.k.a Singular) is non-inherent
3207 {
3208
3/4
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 1873 times.
✓ Branch 2 taken 255 times.
✗ Branch 3 not taken.
2128 if ((MAPFLAG2(i, x, y) == mfSINGLE) && (MAPCOMBOFLAG2(i, x, y) == flag))
3209 {
3210 255 rpos = COMBOPOS_REGION(x, y);
3211 255 }
3212
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1853 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
1873 else if ((MAPFLAG2(i, x, y) == mfSINGLE16) && (MAPCOMBOFLAG2(i, x, y) == flag))
3213 {
3214 20 rpos = COMBOPOS_REGION(x, y);
3215 20 single16 = true;
3216 20 }
3217 2128 }
3218 94827887 }
3219
3220 13546841 out_rpos = rpos;
3221 13546841 out_single16 = single16;
3222
4/4
✓ Branch 0 taken 13544757 times.
✓ Branch 1 taken 2084 times.
✓ Branch 2 taken 13544455 times.
✓ Branch 3 taken 302 times.
13546841 return found_nflag || found_cflag || MAPFFCOMBOFLAG(x,y) == flag;
3223 13546841 }
3224
3225 4477821 bool trigger_secrets_if_flag(int32_t x, int32_t y, int32_t flag, bool setflag)
3226 {
3227
8/8
✓ Branch 0 taken 4477581 times.
✓ Branch 1 taken 240 times.
✓ Branch 2 taken 4475684 times.
✓ Branch 3 taken 1897 times.
✓ Branch 4 taken 4475164 times.
✓ Branch 5 taken 520 times.
✓ Branch 6 taken 952 times.
✓ Branch 7 taken 4474212 times.
4477821 if (x < -16 || y < -16 || x >= world_w || y >= world_h) return false;
3228
3229 4474212 mapscr* scr = NULL;
3230 4474212 int32_t screen = -1;
3231 4474212 rpos_t trigger_rpos = rpos_t::None;
3232 4474212 bool single16 = false;
3233
3234 4474212 std::vector<std::pair<int, int>> coords;
3235
1/2
✓ Branch 0 taken 4474212 times.
✗ Branch 1 not taken.
4474212 coords.push_back({x, y});
3236
1/2
✓ Branch 0 taken 4474212 times.
✗ Branch 1 not taken.
4474212 coords.push_back({x + 15, y});
3237
1/2
✓ Branch 0 taken 4474212 times.
✗ Branch 1 not taken.
4474212 coords.push_back({x, y + 15});
3238
1/2
✓ Branch 0 taken 4474212 times.
✗ Branch 1 not taken.
4474212 coords.push_back({x + 15, y + 15});
3239 4474212 std::vector<rpos_t> rposes_seen;
3240
2/2
✓ Branch 0 taken 4471815 times.
✓ Branch 1 taken 17891566 times.
84820223 for (auto [x, y] : coords)
3241 {
3242
2/4
✓ Branch 0 taken 17891566 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17891566 times.
✗ Branch 3 not taken.
35783132 rpos_t rpos = COMBOPOS_REGION_B(x, y);
3243
2/2
✓ Branch 0 taken 17679183 times.
✓ Branch 1 taken 212383 times.
17891566 if (rpos == rpos_t::None)
3244 212383 continue;
3245
3246
4/6
✓ Branch 0 taken 17679183 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17679183 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 17679172 times.
35358366 if (MAPFFCOMBOFLAG(x, y) == flag)
3247 {
3248
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
22 screen = get_screen_for_world_xy(x, y);
3249 11 break;
3250 }
3251
3252 17679172 bool seen = false;
3253
2/2
✓ Branch 0 taken 13546841 times.
✓ Branch 1 taken 22206797 times.
35753638 for (rpos_t r : rposes_seen)
3254 {
3255
2/2
✓ Branch 0 taken 18074466 times.
✓ Branch 1 taken 4132331 times.
22206797 if (r == rpos)
3256 {
3257 4132331 seen = true;
3258 4132331 break;
3259 }
3260 }
3261
2/2
✓ Branch 0 taken 13546841 times.
✓ Branch 1 taken 4132331 times.
17679172 if (seen)
3262 4132331 continue;
3263
3264
1/2
✓ Branch 0 taken 13546841 times.
✗ Branch 1 not taken.
13546841 rposes_seen.push_back(rpos);
3265
4/6
✓ Branch 0 taken 13546841 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13546841 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2386 times.
✓ Branch 5 taken 13544455 times.
27093682 if (has_flag_trigger(x, y, flag, trigger_rpos, single16))
3266 {
3267
2/4
✓ Branch 0 taken 2386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2386 times.
✗ Branch 3 not taken.
4772 screen = get_screen_for_world_xy(x, y);
3268 2386 break;
3269 }
3270 }
3271
3272
3/4
✓ Branch 0 taken 2397 times.
✓ Branch 1 taken 4471815 times.
✓ Branch 2 taken 2397 times.
✗ Branch 3 not taken.
4474212 if (screen != -1) scr = get_scr(screen);
3273
2/2
✓ Branch 0 taken 2397 times.
✓ Branch 1 taken 4471815 times.
4474212 if (!scr) return false;
3274
3275
2/2
✓ Branch 0 taken 1958 times.
✓ Branch 1 taken 439 times.
2397 if (trigger_rpos == rpos_t::None)
3276 {
3277 1958 checktrigger = true;
3278
1/2
✓ Branch 0 taken 1958 times.
✗ Branch 1 not taken.
1958 trigger_secrets_for_screen(TriggerSource::Unspecified, screen);
3279 1958 }
3280 else
3281 {
3282 439 checktrigger = true;
3283
2/4
✓ Branch 0 taken 439 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 439 times.
✗ Branch 3 not taken.
439 trigger_secrets_for_screen(TriggerSource::Singular, scr, single16, RPOS_TO_POS(trigger_rpos));
3284 }
3285
3286
1/2
✓ Branch 0 taken 2397 times.
✗ Branch 1 not taken.
2397 sfx(scr->secretsfx);
3287
3288
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2391 times.
2397 if(scr->flags6&fTRIGGERFPERM)
3289 {
3290
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 int32_t flags_remaining = findtrigger(screen); //Normal flags
3291
3292
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (flags_remaining)
3293 {
3294
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Z_eventlog("Hit All Triggers->Perm Secret not fulfilled (%d trigger flag%s remain).\n", flags_remaining, flags_remaining>1?"s":"");
3295 3 setflag=false;
3296 3 }
3297
3298 // Only actually trigger secrets now if 1) all triggers are gone and 2) QR qr_ALLTRIG_PERMSEC_NO_TEMP is off, in
3299 // which case only the screen state for mSECRET may be set below.
3300
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if (!flags_remaining && !get_qr(qr_ALLTRIG_PERMSEC_NO_TEMP))
3301 {
3302 trigger_secrets_for_screen(TriggerSource::Unspecified, scr, scr->flags6&fTRIGGERF1631, -1);
3303 }
3304 6 }
3305
3306
5/6
✓ Branch 0 taken 2292 times.
✓ Branch 1 taken 105 times.
✓ Branch 2 taken 2292 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1108 times.
✓ Branch 5 taken 1184 times.
2397 if (setflag && canPermSecret(cur_dmap, screen))
3307
2/2
✓ Branch 0 taken 721 times.
✓ Branch 1 taken 463 times.
1905 if(!(scr->flags5&fTEMPSECRETS))
3308
1/2
✓ Branch 0 taken 721 times.
✗ Branch 1 not taken.
721 setmapflag(scr, mSECRET);
3309
3310 2397 return true;
3311 4477821 }
3312
3313 14814366 void update_slopes()
3314 {
3315
2/2
✓ Branch 0 taken 142356 times.
✓ Branch 1 taken 14814366 times.
14956722 for (auto& p : slopes)
3316 {
3317 142356 slope_object& s = p.second;
3318 142356 s.updateslope(); //sets old x/y poses
3319 }
3320 14814366 }
3321
3322 14407720 void update_freeform_combos()
3323 {
3324 14407720 ffscript_engine(false);
3325
2/2
✓ Branch 0 taken 24172 times.
✓ Branch 1 taken 14383548 times.
14407720 if ( !FFCore.system_suspend[susptUPDATEFFC] )
3326 {
3327 14383548 int wrap_right = world_w + 32;
3328 14383548 int wrap_bottom = world_h + 32;
3329
3330 485611128 for_every_ffc([&](const ffc_handle_t& ffc_handle) {
3331 471227580 mapscr* scr = ffc_handle.scr;
3332 471227580 ffcdata& thisffc = *ffc_handle.ffc;
3333
3334 // Combo 0?
3335
2/2
✓ Branch 0 taken 45000432 times.
✓ Branch 1 taken 426227148 times.
471227580 if(thisffc.data==0)
3336 426227148 return;
3337
3338 // Changer?
3339
2/2
✓ Branch 0 taken 543029 times.
✓ Branch 1 taken 44457403 times.
45000432 if(thisffc.flags&ffc_changer)
3340 543029 return;
3341
3342 // Stationary?
3343
2/2
✓ Branch 0 taken 9844 times.
✓ Branch 1 taken 44447559 times.
44457403 if(thisffc.flags&ffc_stationary)
3344 9844 return;
3345
3346 // Frozen because Hero's holding up an item?
3347
3/4
✓ Branch 0 taken 138282 times.
✓ Branch 1 taken 44309277 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138282 times.
44447559 if(Hero.getHoldClk()>0 && (thisffc.flags&ffc_ignoreholdup)==0)
3348 138282 return;
3349
3350 // Check for changers
3351
2/2
✓ Branch 0 taken 29549248 times.
✓ Branch 1 taken 14760029 times.
44309277 if (thisffc.link==0)
3352 {
3353 442543282 for_some_ffcs([&](const ffc_handle_t& other_ffc_handle) {
3354
2/2
✓ Branch 0 taken 14758493 times.
✓ Branch 1 taken 413024760 times.
427783253 if (ffc_handle.id == other_ffc_handle.id)
3355 14758493 return true;
3356
3357 413024760 ffcdata& otherffc = *other_ffc_handle.ffc;
3358 // Combo 0?
3359
2/2
✓ Branch 0 taken 144690803 times.
✓ Branch 1 taken 268333957 times.
413024760 if(otherffc.data==0)
3360 268333957 return true;
3361
3362 // Not a changer?
3363
2/2
✓ Branch 0 taken 140702626 times.
✓ Branch 1 taken 3988177 times.
144690803 if(!(otherffc.flags&ffc_changer))
3364 140702626 return true;
3365
3366 // Ignore this changer?
3367
4/4
✓ Branch 0 taken 546579 times.
✓ Branch 1 taken 3441598 times.
✓ Branch 2 taken 299257 times.
✓ Branch 3 taken 3142341 times.
3988177 if((otherffc.x.getInt()==thisffc.changer_x&&otherffc.y.getInt()==thisffc.changer_y) || thisffc.flags&ffc_ignorechanger)
3368 845836 return true;
3369
3370
3/4
✓ Branch 0 taken 2721043 times.
✓ Branch 1 taken 421298 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3562 times.
3145903 if((isonline(thisffc.x.getZLong(), thisffc.y.getZLong(), thisffc.prev_changer_x, thisffc.prev_changer_y, otherffc.x.getZLong(), otherffc.y.getZLong()) || // Along the line, or...
3371 ( // At exactly the same position,
3372
2/2
✓ Branch 0 taken 208792 times.
✓ Branch 1 taken 2512251 times.
2721043 (thisffc.x==otherffc.x && thisffc.y==otherffc.y))
3373
2/2
✓ Branch 0 taken 2303459 times.
✓ Branch 1 taken 2512251 times.
208792 ||
3374 //or imprecision and close enough
3375
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
5024502 ( (thisffc.flags&ffc_imprecisionchanger) && ((abs(thisffc.x.getZLong() - otherffc.x.getZLong()) < 10000) && abs(thisffc.y.getZLong() - otherffc.y.getZLong()) < 10000) )
3376 )
3377 && //and...
3378
2/2
✓ Branch 0 taken 3562 times.
✓ Branch 1 taken 2721195 times.
2724757 (thisffc.prev_changer_x>-10000000 && thisffc.prev_changer_y>-10000000)) // This isn't the first frame on this screen
3379 {
3380 3562 zc_ffc_changer(thisffc, otherffc, ffc_handle.id, other_ffc_handle.id);
3381 3562 return false;
3382 }
3383
3384 2721195 return true;
3385 426767155 });
3386 14760029 }
3387
3388
2/2
✓ Branch 0 taken 29549248 times.
✓ Branch 1 taken 14760029 times.
44309277 ffcdata* linked_ffc = thisffc.link ? get_ffc_handle(thisffc.link - 1).ffc : nullptr;
3389
4/4
✓ Branch 0 taken 14760029 times.
✓ Branch 1 taken 29549248 times.
✓ Branch 2 taken 14682739 times.
✓ Branch 3 taken 14866509 times.
44309277 if (linked_ffc ? !linked_ffc->delay : !thisffc.delay)
3390 {
3391
4/4
✓ Branch 0 taken 182609 times.
✓ Branch 1 taken 14683900 times.
✓ Branch 2 taken 85331 times.
✓ Branch 3 taken 97278 times.
14866509 if(thisffc.link && (thisffc.link-1) != ffc_handle.id)
3392 {
3393 97278 thisffc.prev_changer_x = thisffc.x.getZLong();
3394 97278 thisffc.prev_changer_y = thisffc.y.getZLong();
3395 97278 thisffc.x += linked_ffc->vx;
3396 97278 thisffc.y += linked_ffc->vy;
3397 97278 }
3398 else
3399 {
3400 14769231 thisffc.prev_changer_x = thisffc.x.getZLong();
3401 14769231 thisffc.prev_changer_y = thisffc.y.getZLong();
3402 14769231 thisffc.x += thisffc.vx;
3403 14769231 thisffc.y += thisffc.vy;
3404 14769231 thisffc.vx += thisffc.ax;
3405 14769231 thisffc.vy += thisffc.ay;
3406
3407
3408
2/2
✓ Branch 0 taken 444046 times.
✓ Branch 1 taken 14325185 times.
14769231 if(get_qr(qr_OLD_FFC_SPEED_CAP))
3409 {
3410
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14325185 times.
14325185 if(thisffc.vx>128) thisffc.vx=128;
3411
3412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14325185 times.
14325185 if(thisffc.vx<-128) thisffc.vx=-128;
3413
3414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14325185 times.
14325185 if(thisffc.vy>128) thisffc.vy=128;
3415
3416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14325185 times.
14325185 if(thisffc.vy<-128) thisffc.vy=-128;
3417 14325185 }
3418 }
3419 14866509 }
3420 else
3421 {
3422
3/4
✓ Branch 0 taken 1161 times.
✓ Branch 1 taken 76129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1161 times.
29442768 if(!thisffc.link || (thisffc.link-1) == ffc_handle.id)
3423 76129 thisffc.delay--;
3424 }
3425
3426 // Check if the FFC's off the side of the screen
3427
3428 // Left
3429
2/2
✓ Branch 0 taken 10449 times.
✓ Branch 1 taken 14933350 times.
14943799 if(thisffc.x<-32)
3430 {
3431
2/2
✓ Branch 0 taken 253 times.
✓ Branch 1 taken 10196 times.
10449 if(scr->flags6&fWRAPAROUNDFF)
3432 {
3433 253 thisffc.x = wrap_right+(thisffc.x+32);
3434 253 thisffc.solid_update(false);
3435 253 thisffc.prev_changer_y = thisffc.y.getZLong();
3436 // Re-enable previous changer
3437 253 thisffc.changer_x = -1000;
3438 253 thisffc.changer_y = -1000;
3439 253 }
3440
2/2
✓ Branch 0 taken 10127 times.
✓ Branch 1 taken 69 times.
10196 else if(thisffc.x<-64)
3441 {
3442 69 zc_ffc_set(thisffc, 0);
3443 69 thisffc.flags&=~ffc_carryover;
3444 69 }
3445 10449 }
3446 // Right
3447
2/2
✓ Branch 0 taken 14933169 times.
✓ Branch 1 taken 181 times.
14933350 else if(thisffc.x>=wrap_right)
3448 {
3449
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 53 times.
181 if(scr->flags6&fWRAPAROUNDFF)
3450 {
3451 128 thisffc.x = thisffc.x-wrap_right-32;
3452 128 thisffc.solid_update(false);
3453 128 thisffc.prev_changer_y = thisffc.y.getZLong();
3454 128 thisffc.changer_x = -1000;
3455 128 thisffc.changer_y = -1000;
3456 128 }
3457 else
3458 {
3459 53 zc_ffc_set(thisffc, 0);
3460 53 thisffc.flags&=~ffc_carryover;
3461 }
3462 181 }
3463
3464 // Top
3465
2/2
✓ Branch 0 taken 25480 times.
✓ Branch 1 taken 14918319 times.
14943799 if(thisffc.y<-32)
3466 {
3467
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 25472 times.
25480 if(scr->flags6&fWRAPAROUNDFF)
3468 {
3469 8 thisffc.y = wrap_bottom+(thisffc.y+32);
3470 8 thisffc.solid_update(false);
3471 8 thisffc.prev_changer_x = thisffc.x.getZLong();
3472 8 thisffc.changer_x = -1000;
3473 8 thisffc.changer_y = -1000;
3474 8 }
3475
2/2
✓ Branch 0 taken 25155 times.
✓ Branch 1 taken 317 times.
25472 else if(thisffc.y<-64)
3476 {
3477 317 zc_ffc_set(thisffc, 0);
3478 317 thisffc.flags&=~ffc_carryover;
3479 317 }
3480 25480 }
3481 // Bottom
3482
2/2
✓ Branch 0 taken 14917475 times.
✓ Branch 1 taken 844 times.
14918319 else if(thisffc.y>=wrap_bottom)
3483 {
3484
2/2
✓ Branch 0 taken 753 times.
✓ Branch 1 taken 91 times.
844 if(scr->flags6&fWRAPAROUNDFF)
3485 {
3486 753 thisffc.y = thisffc.y-wrap_bottom-32;
3487 753 thisffc.solid_update(false);
3488 753 thisffc.prev_changer_y = thisffc.x.getZLong();
3489 753 thisffc.changer_x = -1000;
3490 753 thisffc.changer_y = -1000;
3491 753 }
3492 else
3493 {
3494 91 zc_ffc_set(thisffc, 0);
3495 91 thisffc.flags&=~ffc_carryover;
3496 }
3497 844 }
3498 14943799 thisffc.solid_update();
3499 441862102 });
3500 14383548 }
3501 14407720 }
3502
3503 bool hitflag(int32_t x, int32_t y, int32_t flagtype, byte layers)
3504 {
3505 for(int q = 0; q < 7; ++q)
3506 {
3507 if(layers&(1<<q)) //if layer is to be checked
3508 if(MAPFLAG2(q-1,x,y)==flagtype||MAPCOMBOFLAG2(q-1,x,y)==flagtype) //matching flag
3509 return true;
3510 }
3511 return false;
3512 }
3513
3514 231 optional<int> nextscr(int screen, int dir)
3515 {
3516 231 auto [m, s] = nextscr2(cur_map, screen, dir);
3517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
231 if (m == -1) return nullopt;
3518 462 return (m<<7) + s;
3519 231 }
3520
3521 1058 std::pair<int32_t, int32_t> nextscr2(int32_t dir)
3522 {
3523 1058 int32_t map = cur_map;
3524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 int32_t screen = screenscrolling ? scrolling_hero_screen : Hero.current_screen;
3525 1058 return nextscr2(map, screen, dir);
3526 }
3527
3528 5576 std::pair<int32_t, int32_t> nextscr2(int map, int screen, int32_t dir)
3529 {
3530 5576 screen = screen_index_direction(screen, (direction)dir);
3531
3532 // need to check for screens on other maps, 's' not valid, etc.
3533 5576 int32_t index = (hero_scr->sidewarpindex >> (dir*2))&3;
3534
3535 // Fun fact: when a scrolling warp is triggered, this function
3536 // is never even called! - Saf
3537
2/2
✓ Branch 0 taken 3326 times.
✓ Branch 1 taken 2250 times.
6120 if(hero_scr->sidewarptype[index] == 3) // scrolling warp
3538 {
3539
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 482 times.
✓ Branch 2 taken 525 times.
✓ Branch 3 taken 546 times.
✓ Branch 4 taken 697 times.
2250 switch(dir)
3540 {
3541 case up:
3542
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 399 times.
482 if(!(hero_scr->flags2&wfUP)) goto nowarp;
3543
3544 83 break;
3545
3546 case down:
3547
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 446 times.
525 if(!(hero_scr->flags2&wfDOWN)) goto nowarp;
3548
3549 79 break;
3550
3551 case left:
3552
2/2
✓ Branch 0 taken 209 times.
✓ Branch 1 taken 337 times.
546 if(!(hero_scr->flags2&wfLEFT)) goto nowarp;
3553
3554 209 break;
3555
3556 case right:
3557
2/2
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 524 times.
697 if(!(hero_scr->flags2&wfRIGHT)) goto nowarp;
3558
3559 173 break;
3560 }
3561
3562 544 map = DMaps[hero_scr->sidewarpdmap[index]].map;
3563 544 screen = hero_scr->sidewarpscr[index] + DMaps[hero_scr->sidewarpdmap[index]].xoff;
3564 544 }
3565
3566 nowarp:
3567
4/4
✓ Branch 0 taken 5512 times.
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 5400 times.
5576 if(screen<0||screen>=128)
3568 176 return {-1, -1};
3569
3570 5400 return {map, screen};
3571 5576 }
3572
3573 403 optional<int> nextscr_mi(int mi, int dir)
3574 {
3575 403 int map = mi/MAPSCRSNORMAL;
3576 403 int screen = mi%MAPSCRSNORMAL;
3577 403 auto [m, s] = nextscr2(map, screen, dir);
3578
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 402 times.
403 if (m == -1) return nullopt;
3579 804 return (m<<7) + s;
3580 403 }
3581
3582 2114 void bombdoor(int32_t x,int32_t y)
3583 {
3584
2/2
✓ Branch 0 taken 2094 times.
✓ Branch 1 taken 20 times.
2114 if (!is_in_world_bounds(x, y))
3585 20 return;
3586
3587 2094 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, 0);
3588 2094 mapscr* scr = rpos_handle.scr;
3589 2094 int screen = scr->screen;
3590 2902 auto [x0, y0] = translate_screen_coordinates_to_world(rpos_handle.screen);
3591 #define CHECK_RECT(x,y,rx1,ry1,rx2,ry2) (isinRect(x,y,x0+rx1,y0+ry1,x0+rx2,y0+ry2))
3592
3593
12/12
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 2015 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 69 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 69 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 69 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 69 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 69 times.
2094 if(scr->door[0]==dBOMB && CHECK_RECT(x,y,100,0,139,48))
3594 {
3595 69 scr->door[0]=dBOMBED;
3596 69 putdoor(scr, scrollbuf, 0, dBOMBED);
3597 69 setmapflag(scr, mDOOR_UP);
3598 69 markBmap(-1, screen);
3599
3600
1/2
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
69 if(auto v = nextscr(screen, up))
3601 {
3602 69 setmapflag_mi(*v, mDOOR_DOWN);
3603 69 markBmap(-1,*v-(get_currdmap()<<7));
3604 69 }
3605 69 }
3606
3607
12/12
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 2045 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 39 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 39 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 39 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 39 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 39 times.
2094 if(scr->door[1]==dBOMB && CHECK_RECT(x,y,100,112,139,176))
3608 {
3609 39 scr->door[1]=dBOMBED;
3610 39 putdoor(scr, scrollbuf, 1, dBOMBED);
3611 39 setmapflag(scr, mDOOR_DOWN);
3612 39 markBmap(-1, rpos_handle.screen);
3613
3614
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 if(auto v = nextscr(rpos_handle.screen, down))
3615 {
3616 39 setmapflag_mi(*v, mDOOR_UP);
3617 39 markBmap(-1,*v-(get_currdmap()<<7));
3618 39 }
3619 39 }
3620
3621
12/12
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 2027 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 51 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 51 times.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 51 times.
✓ Branch 8 taken 16 times.
✓ Branch 9 taken 51 times.
✓ Branch 10 taken 16 times.
✓ Branch 11 taken 51 times.
2094 if(scr->door[2]==dBOMB && CHECK_RECT(x,y,0,60,48,98))
3622 {
3623 51 scr->door[2]=dBOMBED;
3624 51 putdoor(scr, scrollbuf, 2, dBOMBED);
3625 51 setmapflag(scr, mDOOR_LEFT);
3626 51 markBmap(-1, rpos_handle.screen);
3627
3628
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if(auto v = nextscr(rpos_handle.screen, left))
3629 {
3630 51 setmapflag_mi(*v, mDOOR_RIGHT);
3631 51 markBmap(-1,*v-(get_currdmap()<<7));
3632 51 }
3633 51 }
3634
3635
12/12
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 2008 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 72 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 72 times.
✓ Branch 8 taken 14 times.
✓ Branch 9 taken 72 times.
✓ Branch 10 taken 14 times.
✓ Branch 11 taken 72 times.
2094 if(scr->door[3]==dBOMB && CHECK_RECT(x,y,192,60,240,98))
3636 {
3637 72 scr->door[3]=dBOMBED;
3638 72 putdoor(scr, scrollbuf, 3, dBOMBED);
3639 72 setmapflag(scr, mDOOR_RIGHT);
3640 72 markBmap(-1, rpos_handle.screen);
3641
3642
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(auto v = nextscr(rpos_handle.screen, right))
3643 {
3644 72 setmapflag_mi(*v, mDOOR_LEFT);
3645 72 markBmap(-1,*v-(get_currdmap()<<7));
3646 72 }
3647 72 }
3648 2114 }
3649
3650 6520557222 void draw_cmb(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset,
3651 bool over, bool transp)
3652 {
3653 6520557222 auto& cmb = combobuf[cid];
3654
2/2
✓ Branch 0 taken 93673 times.
✓ Branch 1 taken 6520463549 times.
6520557222 if(cmb.animflags & AF_EDITOR_ONLY)
3655 93673 return;
3656
2/2
✓ Branch 0 taken 3445153115 times.
✓ Branch 1 taken 3075310434 times.
6520463549 if(over)
3657 {
3658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3445153115 times.
3445153115 if(cmb.animflags & AF_TRANSPARENT)
3659 transp = !transp;
3660
2/2
✓ Branch 0 taken 319148412 times.
✓ Branch 1 taken 3126004703 times.
3445153115 if(transp)
3661 319148412 overcombotranslucent(dest, x, y, cid, cset, 128);
3662 3126004703 else overcombo(dest, x, y, cid, cset);
3663 3445153115 }
3664 3075310434 else putcombo(dest, x, y, cid, cset);
3665 6520557222 }
3666 6520565670 void draw_cmb_pos(BITMAP* dest, int32_t x, int32_t y, rpos_t rpos, int32_t cid,
3667 int32_t cset, byte layer, bool over, bool transp)
3668 {
3669
2/2
✓ Branch 0 taken 755578275 times.
✓ Branch 1 taken 5764987395 times.
6520565670 if (rpos != rpos_t::None)
3670 {
3671 5764987395 rpos_t plrpos = COMBOPOS_REGION_B(Hero.x+8, Hero.y+8);
3672
2/2
✓ Branch 0 taken 749524 times.
✓ Branch 1 taken 5764237871 times.
5764987395 if (plrpos != rpos_t::None)
3673 {
3674 5764237871 bool dosw = false;
3675
4/4
✓ Branch 0 taken 67632 times.
✓ Branch 1 taken 5764170239 times.
✓ Branch 2 taken 59184 times.
✓ Branch 3 taken 8448 times.
5764237871 if (rpos == hooked_comborpos && (hooked_layerbits & (1<<layer)))
3676 {
3677
1/2
✓ Branch 0 taken 8448 times.
✗ Branch 1 not taken.
8448 if(hooked_undercombos[layer] > -1)
3678 {
3679 draw_cmb(dest, x, y,
3680 hooked_undercombos[layer], hooked_undercombos[layer+7], over, transp);
3681 }
3682 8448 dosw = true;
3683 8448 }
3684
4/4
✓ Branch 0 taken 32720417 times.
✓ Branch 1 taken 5731509006 times.
✓ Branch 2 taken 8448 times.
✓ Branch 3 taken 32711969 times.
5764229423 else if (rpos == plrpos && (hooked_layerbits & (1<<(layer+8))))
3685 {
3686 8448 dosw = true;
3687 8448 }
3688
2/2
✓ Branch 0 taken 5764220975 times.
✓ Branch 1 taken 16896 times.
5764237871 if (dosw)
3689 {
3690
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 16896 times.
✗ Branch 3 not taken.
16896 switch (Hero.switchhookstyle)
3691 {
3692 default: case swPOOF:
3693 break; //Nothing special here
3694 case swFLICKER:
3695 {
3696
2/2
✓ Branch 0 taken 8448 times.
✓ Branch 1 taken 8448 times.
16896 if(abs(Hero.switchhookclk-33)&0b1000)
3697 8448 break; //Drawn this frame
3698 8448 return; //Not drawn this frame
3699 }
3700 case swRISE:
3701 {
3702 //Draw rising up
3703 y -= 8-(abs(Hero.switchhookclk-32)/4);
3704 break;
3705 }
3706 }
3707 8448 }
3708 5764229423 }
3709 5764978947 }
3710
3711 6520557222 draw_cmb(dest, x, y, cid, cset, over, transp);
3712 6520565670 }
3713
3714 // `draw_cmb_pos` only does meaningful work if the combo being drawn is within the bounds of
3715 // the `bmp` bitmap. However, even getting to the point where `puttile16` (for example) knows
3716 // to cull is somewhat expensive. Since it can only draw 16x16 pixels, we can do the equivalent
3717 // culling here by determining the rows/columns that are within the bitmap bounds. This nets
3718 // on the order of ~30 FPS in uncapped mode on my machine, depending on the viewport/region size.
3719 //
3720 // These two inequalities must be true for `draw_cmb_pos` to do anything useful:
3721 //
3722 // -16 < comboPositionX*16 + x < bitmapWidth
3723 // -16 < comboPositionY*16 + y < bitmapHeight
3724 //
3725 // The following start/end values are derived directly from the above.
3726 //
3727 // `x` and `y` are the offsets the combos will be drawn into the bitmap.
3728 40277095 static void get_bounds_for_draw_cmb_calls(BITMAP* bmp, int x, int y, int& start_x, int& end_x, int& start_y, int& end_y)
3729 {
3730 // if (bmp->clip)
3731 // {
3732 // start_x = MAX(0, ceil((bmp->cl - 15 - x) / 16.0));
3733 // end_x = MIN(16, ceil((bmp->cr - x) / 16.0));
3734 // start_y = MAX(0, ceil((bmp->ct - 15 - y) / 16.0));
3735 // end_y = MIN(11, ceil((bmp->cb - y) / 16.0));
3736 // return;
3737 // }
3738
3739
2/2
✓ Branch 0 taken 2181084 times.
✓ Branch 1 taken 38096011 times.
40277095 start_x = MAX(0, ceil((-15 - x) / 16.0));
3740
2/2
✓ Branch 0 taken 2189800 times.
✓ Branch 1 taken 38087295 times.
40277095 end_x = MIN(16, ceil((bmp->w - x) / 16.0));
3741
2/2
✓ Branch 0 taken 38881751 times.
✓ Branch 1 taken 1395344 times.
40277095 start_y = MAX(0, ceil((-15 - y) / 16.0));
3742
2/2
✓ Branch 0 taken 1687375 times.
✓ Branch 1 taken 38589720 times.
40277095 end_y = MIN(11, ceil((bmp->h - y) / 16.0));
3743 40277095 }
3744
3745 187126647 void do_ffc_layer(BITMAP* bmp, int32_t layer, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3746 {
3747
1/2
✓ Branch 0 taken 187126647 times.
✗ Branch 1 not taken.
187126647 if(!show_ffcs) return;
3748 187126647 mapscr* scr = screen_handle.scr;
3749 187126647 mapscr* base_scr = screen_handle.base_scr;
3750
3751 187126647 y += playing_field_offset;
3752
3753 187126647 bool is_overhead = layer == -1000;
3754
2/2
✓ Branch 0 taken 51012026 times.
✓ Branch 1 taken 136114621 times.
187126647 bool is_bg_layer = layer < 0 && !is_overhead;
3755
2/2
✓ Branch 0 taken 34043354 times.
✓ Branch 1 taken 153083293 times.
187126647 int real_layer = is_bg_layer ? abs(layer) : layer;
3756
2/2
✓ Branch 0 taken 187126647 times.
✓ Branch 1 taken 5584648288 times.
5771774935 for(int32_t i = (base_scr->numFFC()-1); i >= 0; --i)
3757 {
3758
2/2
✓ Branch 0 taken 205538146 times.
✓ Branch 1 taken 5379110142 times.
5584648288 if (base_scr->ffcs[i].data == 0)
3759 5379110142 continue;
3760
3/4
✓ Branch 0 taken 37371506 times.
✓ Branch 1 taken 168166640 times.
✓ Branch 2 taken 37371506 times.
✗ Branch 3 not taken.
205538146 if (is_bg_layer && base_scr->ffcs[i].layer == layer)
3761 ; // ffc is set negative, skip bg layer flag checks
3762 else
3763 {
3764
4/4
✓ Branch 0 taken 37371506 times.
✓ Branch 1 taken 168166640 times.
✓ Branch 2 taken 18685753 times.
✓ Branch 3 taken 18685753 times.
205538146 if(real_layer == 2 && (is_bg_layer != XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)))
3765 18685753 continue;
3766
4/4
✓ Branch 0 taken 37371331 times.
✓ Branch 1 taken 149481062 times.
✓ Branch 2 taken 18685753 times.
✓ Branch 3 taken 18685578 times.
186852393 else if (real_layer == 3 && (is_bg_layer != XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)))
3767 18685578 continue;
3768
4/4
✓ Branch 0 taken 149486024 times.
✓ Branch 1 taken 18680791 times.
✓ Branch 2 taken 18685753 times.
✓ Branch 3 taken 130800271 times.
168166815 if (real_layer > -1 && base_scr->ffcs[i].layer != real_layer)
3769 130800271 continue;
3770 }
3771
3772
6/6
✓ Branch 0 taken 3008970 times.
✓ Branch 1 taken 34357574 times.
✓ Branch 2 taken 5110 times.
✓ Branch 3 taken 3003860 times.
✓ Branch 4 taken 2626 times.
✓ Branch 5 taken 2484 times.
37366544 if (screenscrolling && (base_scr->ffcs[i].flags & ffc_carryover) != 0 && screen_handle.screen != scrolling_hero_screen)
3773 2484 continue; //If scrolling, only draw carryover ffcs from newscr and not oldscr.
3774
3775 37364060 base_scr->ffcs[i].draw_ffc(bmp, x, y, is_overhead);
3776 37364060 }
3777 187126647 }
3778 171012378 void _do_current_ffc_layer(BITMAP* bmp, int32_t layer)
3779 {
3780
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 171012378 times.
171012378 if(!show_ffcs) return;
3781 346602978 for_every_base_screen_in_region([&](mapscr* base_scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3782 175590600 screen_handle_t handle = {base_scr, base_scr, base_scr->screen, 0};
3783 175590600 do_ffc_layer(bmp, layer, handle, 0, 0);
3784 175590600 });
3785 171012378 }
3786 76021990 void do_scrolling_layer(BITMAP *bmp, int32_t type, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3787 {
3788 76021990 mapscr* scr = screen_handle.scr;
3789 76021990 mapscr* base_scr = screen_handle.base_scr;
3790
3791
4/4
✓ Branch 0 taken 61891676 times.
✓ Branch 1 taken 14130314 times.
✓ Branch 2 taken 14130314 times.
✓ Branch 3 taken 76021990 times.
76021990 if (type == -3 || type == -4)
3792 {
3793 28260628 y += playing_field_offset;
3794
3795
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
28260628 for(int32_t i = (base_scr->numFFC()-1); i >= 0; --i)
3796 {
3797 if (base_scr->ffcs[i].data == 0)
3798 continue;
3799
3800 if (screenscrolling && (base_scr->ffcs[i].flags & ffc_carryover) != 0 && screen_handle.screen != scrolling_hero_screen)
3801 continue; //If scrolling, only draw carryover ffcs from newscr and not oldscr.
3802
3803 base_scr->ffcs[i].draw_ffc(bmp, x, y, (type==-4));
3804 }
3805 return;
3806 }
3807
3808 76021990 x -= viewport.x;
3809 76021990 y -= viewport.y - playing_field_offset;
3810
3811 76021990 bool over = true, transp = false;
3812 76021990 int layer = screen_handle.layer;
3813
3814
7/8
✓ Branch 0 taken 54766430 times.
✓ Branch 1 taken 21255560 times.
✓ Branch 2 taken 13433029 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 33661403 times.
✓ Branch 5 taken 21105027 times.
✓ Branch 6 taken 3177949 times.
✓ Branch 7 taken 4644582 times.
76021990 switch(type ? type : layer)
3815 {
3816 case -2: //push blocks
3817
2/2
✓ Branch 0 taken 19531089 times.
✓ Branch 1 taken 14130314 times.
33661403 if (scr)
3818 {
3819
2/2
✓ Branch 0 taken 3437471664 times.
✓ Branch 1 taken 24278391 times.
3437057195 for(int32_t i=0; i<176; i++)
3820 {
3821 3437471664 int32_t mf=scr->sflag[i], mf2 = combobuf[scr->data[i]].flag;
3822
3823
10/10
✓ Branch 0 taken 3437301320 times.
✓ Branch 1 taken 170344 times.
✓ Branch 2 taken 3435829348 times.
✓ Branch 3 taken 1471972 times.
✓ Branch 4 taken 3435200365 times.
✓ Branch 5 taken 628983 times.
✓ Branch 6 taken 24420859 times.
✓ Branch 7 taken 3410779506 times.
✓ Branch 8 taken 42762999 times.
✓ Branch 9 taken 16786249 times.
3474519132 if(mf==mfPUSHUD || mf==mfPUSH4 || mf==mfPUSHED || ((mf>=mfPUSHLR)&&(mf<=mfPUSHRINS))
3824
6/8
✓ Branch 0 taken 3432318836 times.
✓ Branch 1 taken 21539330 times.
✓ Branch 2 taken 3432318836 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3432318836 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 37047468 times.
✓ Branch 7 taken 3395271368 times.
3435200365 || mf2==mfPUSHUD || mf2==mfPUSH4 || mf2==mfPUSHED || ((mf2>=mfPUSHLR)&&(mf2<=mfPUSHRINS)))
3825 {
3826
4/4
✓ Branch 0 taken 4772507 times.
✓ Branch 1 taken 695982 times.
✓ Branch 2 taken 3657 times.
✓ Branch 3 taken 4768850 times.
90994487 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3827 5468489 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, true, false);
3828 5468489 }
3829 3417526106 }
3830 24278391 }
3831 38408705 return;
3832
3833 case -1: //over combo
3834
1/2
✓ Branch 0 taken 21105027 times.
✗ Branch 1 not taken.
21105027 if (scr)
3835 {
3836
2/2
✓ Branch 0 taken 3714484752 times.
✓ Branch 1 taken 21105027 times.
3735589779 for(int32_t i=0; i<176; i++)
3837 {
3838
2/2
✓ Branch 0 taken 3695208572 times.
✓ Branch 1 taken 19276180 times.
3714484752 if(combo_class_buf[combobuf[scr->data[i]].type].overhead)
3839 {
3840
4/4
✓ Branch 0 taken 15523337 times.
✓ Branch 1 taken 3752843 times.
✓ Branch 2 taken 22320 times.
✓ Branch 3 taken 15501017 times.
19276180 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3841 19276180 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, true, false);
3842 19276180 }
3843 3714484752 }
3844 21105027 }
3845 21105027 return;
3846
3847 case 1:
3848 case 4:
3849 case 5:
3850 case 6:
3851
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 13433029 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
13433029 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3852 {
3853
1/2
✓ Branch 0 taken 13433029 times.
✗ Branch 1 not taken.
13433029 if (scr)
3854 {
3855
2/2
✓ Branch 0 taken 11773818 times.
✓ Branch 1 taken 1659211 times.
13433029 if(base_scr->layeropacity[layer-1]!=255)
3856 1659211 transp = true;
3857 13433029 break;
3858 }
3859 }
3860 return;
3861
3862 case 2:
3863
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3177949 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3177949 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3864 {
3865
1/2
✓ Branch 0 taken 3177949 times.
✗ Branch 1 not taken.
3177949 if (scr)
3866 {
3867
2/2
✓ Branch 0 taken 2958352 times.
✓ Branch 1 taken 219597 times.
3177949 if(base_scr->layeropacity[layer-1]!=255)
3868 219597 transp = true;
3869
3870
2/2
✓ Branch 0 taken 3049040 times.
✓ Branch 1 taken 128909 times.
3177949 if(XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3871 128909 over = false;
3872
3873 3177949 break;
3874 }
3875 }
3876 return;
3877
3878 case 3:
3879
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4644582 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4644582 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3880 {
3881
1/2
✓ Branch 0 taken 4644582 times.
✗ Branch 1 not taken.
4644582 if (scr)
3882 {
3883
2/2
✓ Branch 0 taken 4570869 times.
✓ Branch 1 taken 73713 times.
4644582 if(base_scr->layeropacity[layer-1]!=255)
3884 73713 transp = true;
3885
3886
2/2
✓ Branch 0 taken 36654 times.
✓ Branch 1 taken 60483 times.
4644582 if(XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)
3887
2/2
✓ Branch 0 taken 97137 times.
✓ Branch 1 taken 4547445 times.
4644582 && !XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3888 60483 over = false;
3889
3890 4644582 break;
3891 }
3892 }
3893 return;
3894 }
3895
3896 int start_x, end_x, start_y, end_y;
3897 21255560 get_bounds_for_draw_cmb_calls(bmp, x, y, start_x, end_x, start_y, end_y);
3898
2/2
✓ Branch 0 taken 21255560 times.
✓ Branch 1 taken 225583635 times.
246839195 for (int cy = start_y; cy < end_y; cy++)
3899 {
3900
2/2
✓ Branch 0 taken 3419020855 times.
✓ Branch 1 taken 225583635 times.
3644604490 for (int cx = start_x; cx < end_x; cx++)
3901 {
3902 3419020855 int i = cx + cy*16;
3903
4/4
✓ Branch 0 taken 3035867404 times.
✓ Branch 1 taken 383153451 times.
✓ Branch 2 taken 10099056 times.
✓ Branch 3 taken 3025768348 times.
3419020855 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3904 3419020855 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, over, transp);
3905 3419020855 }
3906 225583635 }
3907 61891676 }
3908
3909 269084448 bool lenscheck(mapscr* scr, int layer)
3910 {
3911
4/4
✓ Branch 0 taken 268905500 times.
✓ Branch 1 taken 178948 times.
✓ Branch 2 taken 178948 times.
✓ Branch 3 taken 269084448 times.
269084448 if(layer < 0 || layer > 6) return true;
3912
2/2
✓ Branch 0 taken 259626921 times.
✓ Branch 1 taken 9457527 times.
269084448 if(get_qr(qr_OLD_LENS_LAYEREFFECT))
3913 {
3914
2/2
✓ Branch 0 taken 209741101 times.
✓ Branch 1 taken 49885820 times.
259626921 if(!layer) return true;
3915
8/8
✓ Branch 0 taken 34927477 times.
✓ Branch 1 taken 174813624 times.
✓ Branch 2 taken 258970 times.
✓ Branch 3 taken 34668507 times.
✓ Branch 4 taken 143758 times.
✓ Branch 5 taken 163336 times.
✓ Branch 6 taken 326536 times.
✓ Branch 7 taken 34485729 times.
209741101 if((layer==(int32_t)(scr->lens_layer&7)+1) && ((scr->lens_layer&llLENSSHOWS && !lensclk) || (scr->lens_layer&llLENSHIDES && lensclk)))
3916 489872 return false;
3917 209299353 }
3918 else
3919 {
3920
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9457527 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9457527 times.
9457527 if((lensclk ? scr->lens_hide : scr->lens_show) & (1<<layer))
3921 return false;
3922 }
3923 218756880 return true;
3924 268905500 }
3925
3926 156218897 void do_layer(BITMAP *bmp, int32_t type, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3927 {
3928 156218897 bool showlayer = true;
3929 156218897 mapscr* base_scr = screen_handle.base_scr;
3930 156218897 int layer = screen_handle.layer;
3931
2/2
✓ Branch 0 taken 42112241 times.
✓ Branch 1 taken 114106656 times.
156218897 int target = type ? type : layer;
3932
3/4
✓ Branch 0 taken 114106656 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20247437 times.
✓ Branch 3 taken 21864804 times.
156218897 switch(target)
3933 {
3934 case -2:
3935
1/2
✓ Branch 0 taken 20247437 times.
✗ Branch 1 not taken.
20247437 if(!show_layer_push)
3936 showlayer = false;
3937 20247437 break;
3938
3939 case -1:
3940
1/2
✓ Branch 0 taken 21864804 times.
✗ Branch 1 not taken.
21864804 if(!show_layer_over)
3941 showlayer = false;
3942 21864804 break;
3943
3944 case 1: case 2: case 3:
3945 case 4: case 5: case 6:
3946 114106656 showlayer = show_layers[target];
3947 114106656 break;
3948 }
3949
3950
2/2
✓ Branch 0 taken 42112241 times.
✓ Branch 1 taken 114106656 times.
156218897 if(!type)
3951 {
3952
2/2
✓ Branch 0 taken 113970458 times.
✓ Branch 1 taken 136198 times.
114106656 if(!lenscheck(base_scr,layer))
3953 136198 showlayer = false;
3954 114106656 }
3955
3956
2/2
✓ Branch 0 taken 136198 times.
✓ Branch 1 taken 156082699 times.
156218897 if(showlayer)
3957 {
3958
6/6
✓ Branch 0 taken 61947799 times.
✓ Branch 1 taken 94134900 times.
✓ Branch 2 taken 21311683 times.
✓ Branch 3 taken 40636116 times.
✓ Branch 4 taken 56123 times.
✓ Branch 5 taken 21255560 times.
156082699 if (screen_handle.scr && (type || !(base_scr->hidelayers & (1 << (layer)))))
3959 {
3960 61891676 do_scrolling_layer(bmp, type, screen_handle, x, y);
3961
4/4
✓ Branch 0 taken 21255560 times.
✓ Branch 1 taken 40636116 times.
✓ Branch 2 taken 19258730 times.
✓ Branch 3 taken 1996830 times.
61891676 if(!type && !get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3962
2/2
✓ Branch 0 taken 1996254 times.
✓ Branch 1 taken 576 times.
1997406 if(mblock2.draw(bmp,layer))
3963 576 do_primitives(bmp, SPLAYER_MOVINGBLOCK);
3964 61891676 }
3965 156082699 }
3966 156218897 }
3967
3968 103058319 void do_layer_primitives(BITMAP *bmp, int32_t layer)
3969 {
3970 103058319 bool showlayer = true;
3971
3972
2/4
✓ Branch 0 taken 103058319 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 103058319 times.
103058319 if(layer >= 0 && layer <= 6)
3973 {
3974 103058319 showlayer = show_layers[layer];
3975
3976
2/2
✓ Branch 0 taken 102931717 times.
✓ Branch 1 taken 126602 times.
103058319 if(!lenscheck(origin_scr,layer))
3977 126602 showlayer = false;
3978 103058319 }
3979
3980
2/2
✓ Branch 0 taken 126602 times.
✓ Branch 1 taken 102931717 times.
103058319 if (showlayer)
3981 102931717 do_primitives(bmp, layer);
3982 103058319 }
3983
3984 // Called by do_walkflags
3985 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,int32_t xofs,int32_t yofs, word cmbdat,int32_t lyr)
3986 {
3987 newcombo const &c = combobuf[cmbdat];
3988
3989 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
3990
3991 int32_t xx = x-xofs;
3992 int32_t yy = y+playing_field_offset-yofs;
3993
3994 int32_t bridgedetected = 0;
3995
3996 for(int32_t i=0; i<4; i++)
3997 {
3998 int32_t tx=((i&2)<<2)+xx - viewport.x;
3999 int32_t ty=((i&1)<<3)+yy - viewport.y;
4000 int32_t tx2=((i&2)<<2)+x - viewport.x;
4001 int32_t ty2=((i&1)<<3)+y - viewport.y;
4002 for (int32_t j = lyr-1; j <= 1; j++)
4003 {
4004 if (get_qr(qr_OLD_BRIDGE_COMBOS))
4005 {
4006 if (combobuf[MAPCOMBO2(j,tx2,ty2)].type == cBRIDGE && !_walkflag_layer(tx2,ty2,j))
4007 {
4008 bridgedetected |= (1<<i);
4009 }
4010 }
4011 else
4012 {
4013 if (combobuf[MAPCOMBO2(j,tx2,ty2)].type == cBRIDGE && _effectflag_layer(tx2,ty2,j))
4014 {
4015 bridgedetected |= (1<<i);
4016 }
4017 }
4018 }
4019 if ((bridgedetected & (1<<i)))
4020 {
4021 if (i >= 3) break;
4022 else continue;
4023 }
4024 bool doladdercheck = true;
4025
4026 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
4027 {
4028 for(int32_t k=0; k<8; k+=2)
4029 for(int32_t j=0; j<8; j+=2)
4030 if(((k+j)/2)%2)
4031 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,makecol(85,85,255));
4032 }
4033 if (iswater_type(c.type) && !DRIEDLAKE && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) //Yes, I realize this is horribly inaccurate; the alternative is the game chugging every time you turn on walk cheats.
4034 {
4035 if (get_qr(qr_NO_SOLID_SWIM)) doladdercheck = false;
4036 if((lyr==0 || (get_qr(qr_WATER_ON_LAYER_1) && lyr == 1) || (get_qr(qr_WATER_ON_LAYER_2) && lyr == 2)) && get_qr(qr_DROWN))
4037 rectfill(dest,tx,ty,tx+7,ty+7,makecol(85,85,255));
4038 else rectfill(dest,tx,ty,tx+7,ty+7,makecol(170,170,170));
4039 }
4040
4041 if(c.walk&(1<<i) && !(iswater_type(c.type) && DRIEDLAKE) && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) // Check for dried lake (watertype && not water)
4042 {
4043 if(c.type==cLADDERHOOKSHOT && isstepable(cmbdat) && ishookshottable(xx,yy))
4044 {
4045 for(int32_t k=0; k<8; k+=2)
4046 for(int32_t j=0; j<8; j+=2)
4047 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,((k+j)/2)%2 ? makecol(165,105,8) : makecol(170,170,170));
4048 }
4049 else
4050 {
4051 int32_t color = makecol(178,36,36);
4052
4053 if(isstepable(cmbdat)&& (!doladdercheck))
4054 color=makecol(165,105,8);
4055 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(xx,yy))
4056 color=makecol(170,170,170);
4057
4058 rectfill(dest,tx,ty,tx+7,ty+7,color);
4059 }
4060 }
4061 }
4062
4063 // Draw damage combos
4064 bool dmg = combo_class_buf[combobuf[MAPCOMBO2(-1,xx,yy)].type].modify_hp_amount
4065 || combo_class_buf[combobuf[MAPCOMBO2(0,xx,yy)].type].modify_hp_amount
4066 || combo_class_buf[combobuf[MAPCOMBO2(1,xx,yy)].type].modify_hp_amount;
4067
4068 if(dmg)
4069 {
4070 int32_t color = makecol(255,255,0);
4071 if (bridgedetected <= 0)
4072 {
4073 for(int32_t k=0; k<16; k+=2)
4074 for(int32_t j=0; j<16; j+=2)
4075 if(((k+j)/2)%2)
4076 {
4077 int32_t x0 = x - viewport.x;
4078 int32_t y0 = y - viewport.y;
4079 rectfill(dest,x0+k,y0+j,x0+k+1,y0+j+1,color);
4080 }
4081 }
4082 else
4083 {
4084 for(int32_t i=0; i<4; i++)
4085 {
4086 if (!(bridgedetected & (1<<i)))
4087 {
4088 int32_t tx=((i&2)<<2)+x - viewport.x;
4089 int32_t ty=((i&1)<<3)+y - viewport.y;
4090 for(int32_t k=0; k<8; k+=2)
4091 for(int32_t j=0; j<8; j+=2)
4092 if((k+j)%4 < 2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,color);
4093 }
4094 }
4095 }
4096 }
4097 }
4098 static void put_walkflags_a5(int32_t x, int32_t y, word cmbdat, int32_t lyr)
4099 {
4100 ALLEGRO_COLOR col_solid = al_map_rgba(178,36,36,info_opacity);
4101 ALLEGRO_COLOR col_water1 = al_map_rgba(85,85,255,info_opacity);
4102 ALLEGRO_COLOR col_lhook = al_map_rgba(170,170,170,info_opacity);
4103 ALLEGRO_COLOR col_stepable = al_map_rgba(165,105,8,info_opacity);
4104 ALLEGRO_COLOR col_dmg = al_map_rgba(255,255,0,info_opacity);
4105 newcombo const &c = combobuf[cmbdat];
4106
4107 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
4108
4109 int32_t xx = x-viewport.x;
4110 int32_t yy = y+playing_field_offset-viewport.y;
4111
4112 int32_t bridgedetected = 0;
4113
4114 // Draw damage combos
4115 bool dmg = combo_class_buf[c.type].modify_hp_amount;
4116
4117 for(int32_t i=0; i<4; i++)
4118 {
4119 int32_t tx=((i&2)<<2)+xx;
4120 int32_t ty=((i&1)<<3)+yy;
4121 int32_t tx2=((i&2)<<2)+x;
4122 int32_t ty2=((i&1)<<3)+y;
4123 for (int32_t m = lyr-1; m <= 1; m++)
4124 {
4125 if (get_qr(qr_OLD_BRIDGE_COMBOS))
4126 {
4127 if (m >= 0 && combobuf[MAPCOMBO2(m, tx2, ty2)].type == cBRIDGE && !_walkflag_layer(tx2, ty2, m))
4128 {
4129 bridgedetected |= (1<<i);
4130 }
4131 }
4132 else
4133 {
4134 if (m >= 0 && combobuf[MAPCOMBO2(m, tx2, ty2)].type == cBRIDGE && _effectflag_layer(tx2, ty2, m))
4135 {
4136 bridgedetected |= (1<<i);
4137 }
4138 }
4139 }
4140 if ((bridgedetected & (1<<i)))
4141 continue;
4142 bool doladdercheck = true;
4143
4144 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
4145 {
4146 for(int32_t k=0; k<8; k+=2)
4147 for(int32_t j=0; j<8; j+=2)
4148 if(((k+j)/2)%2)
4149 al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,col_water1);
4150 }
4151 if (iswater_type(c.type) && !DRIEDLAKE && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) //Yes, I realize this is horribly inaccurate; the alternative is the game chugging every time you turn on walk cheats.
4152 {
4153 if (get_qr(qr_NO_SOLID_SWIM)) doladdercheck = false;
4154 if((lyr==0 || (get_qr(qr_WATER_ON_LAYER_1) && lyr == 1) || (get_qr(qr_WATER_ON_LAYER_2) && lyr == 2)) && get_qr(qr_DROWN))
4155 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_water1);
4156 else al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_lhook);
4157 }
4158
4159 if(c.walk&(1<<i) && !(iswater_type(c.type) && DRIEDLAKE) && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) // Check for dried lake (watertype && not water)
4160 {
4161 if(c.type==cLADDERHOOKSHOT && isstepable(cmbdat) && ishookshottable(xx,yy))
4162 {
4163 for(int32_t k=0; k<8; k+=2)
4164 for(int32_t j=0; j<8; j+=2)
4165 al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,((k+j)/2)%2 ? col_stepable : col_lhook);
4166 }
4167 else
4168 {
4169 ALLEGRO_COLOR* color = &col_solid;
4170
4171 if(isstepable(cmbdat)&& (!doladdercheck))
4172 color=&col_stepable;
4173 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(xx,yy))
4174 color=&col_lhook;
4175
4176 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,*color);
4177 }
4178 }
4179
4180 if(dmg)
4181 {
4182 for(int32_t k=0; k<8; k+=2)
4183 for(int32_t j=0; j<8; j+=2)
4184 if((k+j)%4 < 2) al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,col_dmg);
4185 }
4186 }
4187 }
4188
4189 void put_effectflags(BITMAP *dest,int32_t x,int32_t y,int32_t xofs,int32_t yofs, word cmbdat,int32_t lyr)
4190 {
4191 newcombo const &c = combobuf[cmbdat];
4192
4193 int32_t xx = x-xofs-viewport.x;
4194 int32_t yy = y+playing_field_offset-yofs-viewport.y;
4195
4196 for(int32_t i=0; i<4; i++)
4197 {
4198 int32_t tx=((i&2)<<2)+xx;
4199 int32_t ty=((i&1)<<3)+yy;
4200
4201 if(((c.walk>>4)&(1<<i)) && c.type != cNONE)
4202 {
4203 int32_t color = vc(10);
4204
4205 rectfill(dest,tx,ty,tx+7,ty+7,color);
4206 }
4207 }
4208 }
4209 static void put_effectflags_a5(int32_t x, int32_t y, word cmbdat, int32_t lyr)
4210 {
4211 ALLEGRO_COLOR col_eff = al_map_rgba(85,255,85,info_opacity);
4212 newcombo const &c = combobuf[cmbdat];
4213
4214 int32_t xx = x-viewport.x;
4215 int32_t yy = y+playing_field_offset-viewport.y;
4216
4217 for(int32_t i=0; i<4; i++)
4218 {
4219 int32_t tx=((i&2)<<2)+xx;
4220 int32_t ty=((i&1)<<3)+yy;
4221
4222 if(((c.walk>>4)&(1<<i)) && c.type != cNONE)
4223 {
4224 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_eff);
4225 }
4226 }
4227 }
4228
4229 void draw_ladder_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
4230 {
4231 for(auto cx = 0; cx < 256; cx += 16)
4232 {
4233 for(auto cy = 0; cy < 176; cy += 16)
4234 {
4235 if(isSVLadder(cx,cy))
4236 {
4237 auto nx = cx+x, ny = cy+y;
4238 if(cy && !isSVLadder(cx,cy-16))
4239 line(dest,nx,ny,nx+15,ny,c);
4240 rectfill(dest,nx,ny,nx+3,ny+15,c);
4241 rectfill(dest,nx+12,ny,nx+15,ny+15,c);
4242 rectfill(dest,nx+4,ny+2,nx+11,ny+5,c);
4243 rectfill(dest,nx+4,ny+10,nx+11,ny+13,c);
4244 }
4245 else if(isSVPlatform(cx,cy))
4246 {
4247 line(dest,cx+x,cy+y,cx+x+15,cy+y,c);
4248 }
4249 }
4250 }
4251 }
4252 void draw_ladder_platform_a5(int32_t x, int32_t y, ALLEGRO_COLOR c)
4253 {
4254 for(auto cx = 0; cx < 256; cx += 16)
4255 {
4256 for(auto cy = 0; cy < 176; cy += 16)
4257 {
4258 if(isSVLadder(cx,cy))
4259 {
4260 auto nx = cx+x, ny = cy+y;
4261 if(cy && !isSVLadder(cx,cy-16))
4262 al_draw_line(nx,ny,nx+15,ny,c,1);
4263 al_draw_filled_rectangle(nx,ny,nx+4,ny+16,c);
4264 al_draw_filled_rectangle(nx+12,ny,nx+16,ny+16,c);
4265 al_draw_filled_rectangle(nx+4,ny+2,nx+12,ny+6,c);
4266 al_draw_filled_rectangle(nx+4,ny+10,nx+12,ny+14,c);
4267 }
4268 else if(isSVPlatform(cx,cy))
4269 {
4270 al_draw_line(cx+x,cy+y,cx+x+15,cy+y,c,1);
4271 }
4272 }
4273 }
4274 }
4275
4276 // Walkflags L4 cheat
4277 void do_walkflags(const screen_handles_t& screen_handles, int32_t x, int32_t y)
4278 {
4279 if (!show_walkflags)
4280 return;
4281
4282 start_info_bmp();
4283
4284 mapscr* scr = screen_handles[0].scr;
4285 for(int32_t i=0; i<176; i++)
4286 {
4287 put_walkflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], 0);
4288 }
4289
4290 for(int32_t k=0; k<2; k++)
4291 {
4292 scr = screen_handles[k + 1].scr;
4293
4294 if (scr)
4295 {
4296 for(int32_t i=0; i<176; i++)
4297 {
4298 put_walkflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], k%2+1);
4299 }
4300 }
4301 }
4302
4303 end_info_bmp();
4304 }
4305
4306 void do_walkflags(int32_t x, int32_t y)
4307 {
4308 if (!show_walkflags)
4309 return;
4310
4311 x += -viewport.x;
4312 y += playing_field_offset - viewport.y;
4313
4314 start_info_bmp();
4315
4316 draw_ladder_platform_a5(x,y,al_map_rgba(165,105,8,info_opacity));
4317 draw_solid_objects_a5(x,y,al_map_rgba(178,36,36,info_opacity));
4318 draw_slopes_a5(x,y,al_map_rgba(255,85,255,info_opacity));
4319
4320 end_info_bmp();
4321 }
4322
4323 // Effectflags L4 cheat
4324 void do_effectflags(mapscr* scr, int32_t x, int32_t y)
4325 {
4326 if(show_effectflags)
4327 {
4328 start_info_bmp();
4329
4330 for(int32_t i=0; i<176; i++)
4331 {
4332 put_effectflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], 0);
4333 }
4334
4335 end_info_bmp();
4336 }
4337 }
4338
4339 272141 void calc_darkroom_combos(mapscr* scr, int offx, int offy)
4340 {
4341 272141 int map = scr->map;
4342 272141 int screen = scr->screen;
4343
4344
2/2
✓ Branch 0 taken 1904987 times.
✓ Branch 1 taken 272141 times.
2177128 for(int32_t lyr = 0; lyr < 7; ++lyr)
4345 {
4346 1904987 mapscr* scr = get_scr_layer(map, screen, lyr);
4347
2/2
✓ Branch 0 taken 1279588 times.
✓ Branch 1 taken 625399 times.
1904987 if (!scr->is_valid()) continue;
4348
4349
2/2
✓ Branch 0 taken 225207488 times.
✓ Branch 1 taken 1279588 times.
226487076 for(int32_t q = 0; q < 176; ++q)
4350 {
4351 225207488 newcombo const& cmb = combobuf[scr->data[q]];
4352
2/2
✓ Branch 0 taken 224602869 times.
✓ Branch 1 taken 604619 times.
225207488 if(cmb.type == cTORCH)
4353 {
4354 604619 do_torch_combo(cmb, COMBOX(q)+8+offx, COMBOY(q)+8+offy, darkscr_bmp);
4355 604619 }
4356 225207488 }
4357 1279588 }
4358 272141 }
4359
4360 272141 void calc_darkroom_ffcs(mapscr* scr, int offx, int offy)
4361 {
4362 272141 word c = scr->numFFC();
4363
2/2
✓ Branch 0 taken 537406 times.
✓ Branch 1 taken 272141 times.
809547 for(int q = 0; q < c; ++q)
4364 {
4365 537406 newcombo const& cmb = combobuf[scr->ffcs[q].data];
4366
2/2
✓ Branch 0 taken 522598 times.
✓ Branch 1 taken 14808 times.
537406 if(cmb.type == cTORCH)
4367 {
4368 14808 int cx = scr->ffcs[q].x.getInt()+(scr->ffEffectWidth(q)/2)+offx;
4369 14808 int cy = (scr->ffcs[q].y.getInt())+(scr->ffEffectHeight(q)/2)+offy;
4370 14808 do_torch_combo(cmb, cx, cy, darkscr_bmp);
4371 14808 }
4372 537406 }
4373 272141 }
4374
4375 struct nearby_screen_t
4376 {
4377 int screen;
4378 int offx;
4379 int offy;
4380 screen_handles_t screen_handles;
4381 };
4382 typedef std::vector<nearby_screen_t> nearby_screens_t;
4383
4384 15493294 static nearby_screens_t get_nearby_screens_non_scrolling_region()
4385 {
4386 15493294 nearby_screens_t nearby_screens;
4387
4388 15493294 mapscr* base_scr = origin_scr;
4389
1/2
✓ Branch 0 taken 15493294 times.
✗ Branch 1 not taken.
15493294 auto& nearby_screen = nearby_screens.emplace_back();
4390 15493294 nearby_screen.screen = cur_screen;
4391
1/2
✓ Branch 0 taken 15493294 times.
✗ Branch 1 not taken.
15493294 nearby_screen.screen_handles = create_screen_handles(base_scr);
4392
4393 15493294 return nearby_screens;
4394
1/2
✓ Branch 0 taken 15493294 times.
✗ Branch 1 not taken.
15493294 }
4395
4396 48296 static nearby_screens_t get_nearby_screens_scrolling_region()
4397 {
4398 48296 nearby_screens_t nearby_screens;
4399
4400
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_x0 = viewport.left() / 256;
4401
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_x1 = (viewport.right() - 1) / 256;
4402
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_y0 = viewport.top() / 176;
4403
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_y1 = (viewport.bottom() - 1) / 176;
4404
4405
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_x0 = std::clamp(screens_x0, 0, 15);
4406
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_x1 = std::clamp(screens_x1, 0, 15);
4407
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_y0 = std::clamp(screens_y0, 0, 8);
4408
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_y1 = std::clamp(screens_y1, 0, 8);
4409
4410
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 79928 times.
128224 for (int x = screens_x0; x <= screens_x1; x++)
4411 {
4412
2/2
✓ Branch 0 taken 169672 times.
✓ Branch 1 taken 79928 times.
249600 for (int y = screens_y0; y <= screens_y1; y++)
4413 {
4414 169672 int screen = cur_screen + x + y*16;
4415
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 if (!is_in_current_region(screen)) continue;
4416
4417
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 mapscr* base_scr = get_scr(screen);
4418
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 if (!base_scr->is_valid()) continue;
4419
4420
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
4421
4422
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 auto& nearby_screen = nearby_screens.emplace_back();
4423 169672 nearby_screen.screen = screen;
4424 169672 nearby_screen.offx = offx;
4425 169672 nearby_screen.offy = offy;
4426
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 nearby_screen.screen_handles = create_screen_handles(base_scr);
4427 169672 }
4428 79928 }
4429
4430 48296 return nearby_screens;
4431
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 }
4432
4433 3658 static nearby_screens_t get_nearby_screens_smooth_maze()
4434 {
4435 3658 nearby_screens_t nearby_screens;
4436
4437
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_x0 = viewport.left() / 256;
4438
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_x1 = (viewport.right() - 1) / 256;
4439
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_y0 = viewport.top() / 176;
4440
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_y1 = (viewport.bottom() - 1) / 176;
4441
4442
2/4
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
3658 if (viewport.left() < 0) screens_x0--;
4443
2/4
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
3658 if (viewport.top() < 0) screens_y0--;
4444
4445
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 7308 times.
10966 for (int x = screens_x0; x <= screens_x1; x++)
4446 {
4447
2/2
✓ Branch 0 taken 18600 times.
✓ Branch 1 taken 7308 times.
25908 for (int y = screens_y0; y <= screens_y1; y++)
4448 {
4449 18600 int screen = -1;
4450 mapscr* base_scr;
4451 int offx, offy;
4452
4453 18600 mapscr* maze_scr = maze_state.scr;
4454 18600 int maze_screen = maze_scr->screen;
4455
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 int maze_screen_x = get_region_relative_dx(maze_screen);
4456
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 int maze_screen_y = get_region_relative_dy(maze_screen);
4457 18600 int maze_screen_dx = x - maze_screen_x;
4458 18600 int maze_screen_dy = y - maze_screen_y;
4459 18600 int exitdir = maze_scr->exitdir;
4460
4461 bool should_draw_maze_screen;
4462
2/2
✓ Branch 0 taken 9052 times.
✓ Branch 1 taken 9548 times.
18600 if (maze_state.lost)
4463 {
4464 9548 should_draw_maze_screen = true;
4465 9548 }
4466 else
4467 {
4468 9052 should_draw_maze_screen = true;
4469
4/6
✓ Branch 0 taken 9052 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6844 times.
✓ Branch 3 taken 2208 times.
✓ Branch 4 taken 6844 times.
✗ Branch 5 not taken.
9052 should_draw_maze_screen &= XY_DELTA_TO_DIR(maze_screen_dx, 0) != exitdir && XY_DELTA_TO_DIR(0, maze_screen_dy) != exitdir;
4470
2/2
✓ Branch 0 taken 3850 times.
✓ Branch 1 taken 5202 times.
9052 if (maze_state.enter_dir != dir_invalid)
4471
4/6
✓ Branch 0 taken 3850 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3304 times.
✓ Branch 3 taken 546 times.
✓ Branch 4 taken 3304 times.
✗ Branch 5 not taken.
3850 should_draw_maze_screen &= XY_DELTA_TO_DIR(maze_screen_dx, 0) != maze_state.enter_dir && XY_DELTA_TO_DIR(0, maze_screen_dy) != maze_state.enter_dir;
4472 }
4473
4474
2/2
✓ Branch 0 taken 16048 times.
✓ Branch 1 taken 2552 times.
18600 if (should_draw_maze_screen)
4475 {
4476 16048 screen = maze_state.scr->screen;
4477 16048 base_scr = maze_state.scr;
4478
1/2
✓ Branch 0 taken 16048 times.
✗ Branch 1 not taken.
16048 std::tie(offx, offy) = translate_screen_coordinates_to_world(cur_screen + x + y*16);
4479 16048 }
4480
4481
2/2
✓ Branch 0 taken 16048 times.
✓ Branch 1 taken 2552 times.
18600 if (screen == -1)
4482 {
4483 2552 screen = cur_screen + x + y*16;
4484
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 if (!is_in_current_region(screen)) continue;
4485
4486
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 base_scr = get_scr(screen);
4487
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 if (!base_scr->is_valid()) continue;
4488
4489
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 std::tie(offx, offy) = translate_screen_coordinates_to_world(screen);
4490 2552 }
4491
4492
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 auto& nearby_screen = nearby_screens.emplace_back();
4493 18600 nearby_screen.screen = screen;
4494 18600 nearby_screen.offx = offx;
4495 18600 nearby_screen.offy = offy;
4496
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 nearby_screen.screen_handles = create_screen_handles(base_scr);
4497 18600 }
4498 7308 }
4499
4500 3658 return nearby_screens;
4501
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 }
4502
4503 15545248 static nearby_screens_t get_nearby_screens()
4504 {
4505
4/4
✓ Branch 0 taken 9214 times.
✓ Branch 1 taken 15536034 times.
✓ Branch 2 taken 3658 times.
✓ Branch 3 taken 5556 times.
15545248 if (maze_state.active && maze_state.loopy)
4506 3658 return get_nearby_screens_smooth_maze();
4507
4508
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 15493294 times.
15541590 if (is_in_scrolling_region())
4509 48296 return get_nearby_screens_scrolling_region();
4510
4511 15493294 return get_nearby_screens_non_scrolling_region();
4512 15545248 }
4513
4514 202109717 static void for_every_nearby_screen(const nearby_screens_t& nearby_screens, const std::function <void (screen_handles_t, int, int, int)>& fn)
4515 {
4516
2/2
✓ Branch 0 taken 203894319 times.
✓ Branch 1 taken 202109717 times.
406004036 for (auto& nearby_screen : nearby_screens)
4517 203894319 fn(nearby_screen.screen_handles, nearby_screen.screen, nearby_screen.offx, nearby_screen.offy);
4518 202109717 }
4519
4520 124361984 static void draw_msgstr(byte layer, BITMAP* dest = nullptr)
4521 {
4522
2/2
✓ Branch 0 taken 15545248 times.
✓ Branch 1 taken 108816736 times.
124361984 if(layer != msgstr_layer) return;
4523
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 if(!dest) dest = framebuf;
4524
4525
2/2
✓ Branch 0 taken 679438 times.
✓ Branch 1 taken 14865810 times.
15545248 if(!(msg_bg_display_buf->clip))
4526 {
4527 679438 blit_msgstr_bg(dest,0,0,0,playing_field_offset,256,176);
4528 679438 }
4529
4530
2/2
✓ Branch 0 taken 679438 times.
✓ Branch 1 taken 14865810 times.
15545248 if(!(msg_portrait_display_buf->clip))
4531 {
4532 679438 blit_msgstr_prt(dest,0,0,0,playing_field_offset,256,176);
4533 679438 }
4534
4535
2/2
✓ Branch 0 taken 692845 times.
✓ Branch 1 taken 14852403 times.
15545248 if(!(msg_txt_display_buf->clip))
4536 {
4537 692845 blit_msgstr_fg(dest,0,0,0,playing_field_offset,256,176);
4538 692845 }
4539 124361984 }
4540
4541 static void putscrdoors(const nearby_screens_t& nearby_screens, BITMAP *dest, int32_t x, int32_t y);
4542
4543 62180992 static void set_draw_screen_clip(BITMAP* bmp)
4544 {
4545 62180992 set_clip_rect(bmp, draw_screen_clip_rect_x1, draw_screen_clip_rect_y1, draw_screen_clip_rect_x2, draw_screen_clip_rect_y2);
4546 62180992 }
4547
4548 17580 static void draw_sprites(BITMAP* dest, set<sprite*, SpriteSorter>& sprite_set, set<sprite*, SpriteSorter>::iterator& it, word upto_z)
4549 {
4550 17580 bool checkz = upto_z != word(-1); // max value represents "infinity" height
4551
6/6
✓ Branch 0 taken 11145 times.
✓ Branch 1 taken 6435 times.
✓ Branch 2 taken 160 times.
✓ Branch 3 taken 6275 times.
✓ Branch 4 taken 12905 times.
✓ Branch 5 taken 4675 times.
17580 if(it == sprite_set.end() || (checkz && (*it)->total_z() >= upto_z))
4552 12905 return; // no sprites to draw remaining
4553 // Just clips sprites if in a repeating, smooth maze.
4554
1/2
✓ Branch 0 taken 4675 times.
✗ Branch 1 not taken.
4675 bool do_clip = maze_state.active && maze_state.loopy;
4555
4556
4557
1/2
✓ Branch 0 taken 4675 times.
✗ Branch 1 not taken.
4675 if(do_clip)
4558 {
4559 int maze_screen = maze_state.scr->screen;
4560 auto [sx, sy] = translate_screen_coordinates_to_world(maze_screen);
4561 set_clip_rect(dest, sx - viewport.x, sy - viewport.y, sx + 256 - viewport.x, sy + 176 - viewport.y);
4562 }
4563
6/6
✓ Branch 0 taken 2930 times.
✓ Branch 1 taken 32443 times.
✓ Branch 2 taken 160 times.
✓ Branch 3 taken 32283 times.
✓ Branch 4 taken 4675 times.
✓ Branch 5 taken 30698 times.
67816 while(it != sprite_set.end() && (!checkz || (*it)->total_z() < upto_z))
4564 {
4565 30698 sprite* spr = *it;
4566
2/2
✓ Branch 0 taken 27768 times.
✓ Branch 1 taken 2930 times.
30698 if(spr == &Hero) // Draw the Hero
4567 {
4568 2930 decorations.draw2(dest,true);
4569 2930 Hero.draw(dest);
4570 2930 decorations.draw(dest,true);
4571
4572 // Draw enemies holding the Hero directly above the Hero
4573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2930 times.
2930 for(int32_t i=0; i<guys.Count(); i++)
4574 {
4575 if(((enemy*)guys.spr(i))->type == eeWALK)
4576 if(((eStalfos*)guys.spr(i))->hashero)
4577 guys.spr(i)->draw(dest);
4578 else if(((enemy*)guys.spr(i))->type == eeWALLM)
4579 if(((eWallM*)guys.spr(i))->hashero)
4580 guys.spr(i)->draw(dest);
4581 }
4582 2930 }
4583
2/2
✓ Branch 0 taken 24838 times.
✓ Branch 1 taken 2930 times.
27768 else if(spr == &mblock2) // Draw the moving pushblock
4584 {
4585 2930 mblock2.draw(dest, -1);
4586 2930 do_primitives(dest, SPLAYER_MOVINGBLOCK);
4587 2930 }
4588
2/4
✓ Branch 0 taken 24838 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24838 times.
24838 else if(enemy* e = dynamic_cast<enemy*>(spr))
4589 {
4590 e->draw(dest);
4591 e->draw2(dest); // used specifically for eGleeok/esGleeok
4592 }
4593 24838 else spr->draw(dest);
4594 30698 ++it;
4595 }
4596
1/2
✓ Branch 0 taken 4675 times.
✗ Branch 1 not taken.
4675 if(do_clip)
4597 clear_clip_rect(dest);
4598 17580 }
4599
4600 15545248 void draw_screen(bool showhero, bool runGeneric)
4601 {
4602 15545248 bool classic_draw = get_qr(qr_CLASSIC_DRAWING_ORDER);
4603 15545248 clear_info_bmp();
4604
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15545248 times.
15545248 if((GameFlags & (GAMEFLAG_SCRIPTMENU_ACTIVE|GAMEFLAG_F6SCRIPT_ACTIVE))!=0)
4605 {
4606 FFCore.doScriptMenuDraws();
4607 return;
4608 }
4609
4610
2/2
✓ Branch 0 taken 601797 times.
✓ Branch 1 taken 14943451 times.
15545248 if(runGeneric) FFCore.runGenericPassiveEngine(SCR_TIMING_PRE_DRAW);
4611
4612 15545248 clear_bitmap(framebuf);
4613 15545248 clear_clip_rect(framebuf);
4614
4615 15545248 int32_t cmby2=0;
4616
4617 // Draw some background layers
4618 15545248 clear_bitmap(scrollbuf);
4619
4620 15545248 auto nearby_screens = get_nearby_screens();
4621
4622
2/2
✓ Branch 0 taken 15542318 times.
✓ Branch 1 taken 2930 times.
15545248 if (!classic_draw)
4623 {
4624
2/2
✓ Branch 0 taken 11720 times.
✓ Branch 1 taken 2930 times.
14650 for (int layer = -7; layer <= -4; ++layer)
4625 {
4626
1/2
✓ Branch 0 taken 11720 times.
✗ Branch 1 not taken.
11720 _do_current_ffc_layer(framebuf, layer);
4627
2/4
✓ Branch 0 taken 11720 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11720 times.
11720 if (script_drawing_commands.is_dirty(layer))
4628 do_primitives(scrollbuf, layer);
4629 11720 }
4630 2930 }
4631
4632 // Handle layer 2/3 possibly being background layers.
4633
2/2
✓ Branch 0 taken 2930 times.
✓ Branch 1 taken 15542318 times.
15545248 if (classic_draw) // weird ordering (-3 > -2)
4634 {
4635
1/2
✓ Branch 0 taken 15542318 times.
✗ Branch 1 not taken.
31220954 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4636 15678636 mapscr* base_scr = screen_handles[0].base_scr;
4637
2/2
✓ Branch 0 taken 15551355 times.
✓ Branch 1 taken 127281 times.
15678636 if (XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4638 127281 do_layer(scrollbuf, 0, screen_handles[2], offx, offy);
4639 15678636 });
4640
4641 15542318 bool l2bg = XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG);
4642
2/2
✓ Branch 0 taken 127281 times.
✓ Branch 1 taken 15415037 times.
15542318 if (l2bg)
4643 {
4644
1/2
✓ Branch 0 taken 127281 times.
✗ Branch 1 not taken.
127281 do_layer_primitives(scrollbuf, 2);
4645
1/2
✓ Branch 0 taken 127281 times.
✗ Branch 1 not taken.
127281 particles.draw(scrollbuf, true, 2);
4646 127281 }
4647
1/2
✓ Branch 0 taken 15542318 times.
✗ Branch 1 not taken.
15542318 _do_current_ffc_layer(scrollbuf, -2);
4648
2/2
✓ Branch 0 taken 127281 times.
✓ Branch 1 taken 15415037 times.
15542318 if (l2bg)
4649
1/2
✓ Branch 0 taken 127281 times.
✗ Branch 1 not taken.
127281 draw_msgstr(2, scrollbuf);
4650 15542318 }
4651
4652
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4653 15681566 mapscr* base_scr = screen_handles[0].base_scr;
4654
2/2
✓ Branch 0 taken 15588907 times.
✓ Branch 1 taken 92659 times.
15681566 if (XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4655 92659 do_layer(scrollbuf, 0, screen_handles[3], offx, offy);
4656 15681566 });
4657
4658
2/2
✓ Branch 0 taken 92659 times.
✓ Branch 1 taken 15452589 times.
15545248 if (XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4659 {
4660
1/2
✓ Branch 0 taken 92659 times.
✗ Branch 1 not taken.
92659 do_layer_primitives(scrollbuf, 3);
4661
1/2
✓ Branch 0 taken 92659 times.
✗ Branch 1 not taken.
92659 particles.draw(scrollbuf, true, 3);
4662 92659 }
4663
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(scrollbuf, -3);
4664
2/2
✓ Branch 0 taken 92659 times.
✓ Branch 1 taken 15452589 times.
15545248 if (XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4665
1/2
✓ Branch 0 taken 92659 times.
✗ Branch 1 not taken.
92659 draw_msgstr(3, scrollbuf);
4666
4667
2/2
✓ Branch 0 taken 2930 times.
✓ Branch 1 taken 15542318 times.
15545248 if (!classic_draw)
4668 {
4669
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 do_primitives(scrollbuf, -3);
4670 // Actually use proper ordering (-3 < -2)
4671
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
5860 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4672 2930 mapscr* base_scr = screen_handles[0].base_scr;
4673
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 if (XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4674 do_layer(scrollbuf, 0, screen_handles[2], offx, offy);
4675 2930 });
4676
4677 2930 bool l2bg = XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG);
4678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2930 times.
2930 if (l2bg)
4679 {
4680 do_layer_primitives(scrollbuf, 2);
4681 particles.draw(scrollbuf, true, 2);
4682 }
4683
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 _do_current_ffc_layer(scrollbuf, -2);
4684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2930 times.
2930 if (l2bg)
4685 draw_msgstr(2, scrollbuf);
4686
4687
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 do_primitives(scrollbuf, -2);
4688
4689
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 _do_current_ffc_layer(framebuf, -1);
4690
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 do_primitives(scrollbuf, -1);
4691 2930 }
4692
4693 // Draw the main combo screens ("layer 0").
4694
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4695 15681566 mapscr* base_scr = screen_handles[0].base_scr;
4696
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15681566 times.
15681566 if (lenscheck(base_scr, 0))
4697 {
4698 15681566 putscr(base_scr, scrollbuf, offx, offy + playing_field_offset);
4699 15681566 }
4700 15681566 });
4701
4702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15545248 times.
15545248 if (lenscheck(hero_scr, 0))
4703 {
4704
2/2
✓ Branch 0 taken 466049 times.
✓ Branch 1 taken 15079199 times.
15545248 if(!get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4705
3/4
✓ Branch 0 taken 466049 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4136 times.
✓ Branch 3 taken 461913 times.
470185 if(mblock2.draw(scrollbuf,0))
4706
1/2
✓ Branch 0 taken 4136 times.
✗ Branch 1 not taken.
4136 do_primitives(scrollbuf, SPLAYER_MOVINGBLOCK);
4707 15545248 }
4708
4709 // Lens hints, then primitives, then particles.
4710
6/10
✓ Branch 0 taken 15535219 times.
✓ Branch 1 taken 10029 times.
✓ Branch 2 taken 15535219 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15535219 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5876 times.
✓ Branch 9 taken 4153 times.
15545248 if((lensclk || (get_debug() && zc_getkey(KEY_L))) && !get_qr(qr_OLDLENSORDER))
4711 {
4712
1/2
✓ Branch 0 taken 5876 times.
✗ Branch 1 not taken.
5876 draw_lens_under(scrollbuf, false);
4713
1/2
✓ Branch 0 taken 5876 times.
✗ Branch 1 not taken.
5876 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_1);
4714 5876 }
4715
4716
2/4
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15545248 times.
✗ Branch 3 not taken.
15545248 if(show_layers[0] && lenscheck(hero_scr,0))
4717
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 do_primitives(scrollbuf, 0);
4718
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 particles.draw(scrollbuf, true, 0);
4719
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(scrollbuf, 0);
4720
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 draw_msgstr(0, scrollbuf);
4721
4722
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 set_draw_screen_clip(scrollbuf);
4723
4724 15545248 bool hero_draw_done = false;
4725
4/6
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15510496 times.
✓ Branch 3 taken 34752 times.
✓ Branch 4 taken 15510496 times.
✗ Branch 5 not taken.
15545248 bool is_cave_walking = ((Hero.getAction()==climbcovertop)||(Hero.getAction()==climbcoverbottom));
4726
2/2
✓ Branch 0 taken 343259 times.
✓ Branch 1 taken 15201989 times.
15545248 if(!(get_qr(qr_LAYER12UNDERCAVE)))
4727 {
4728
4/4
✓ Branch 0 taken 15200115 times.
✓ Branch 1 taken 1874 times.
✓ Branch 2 taken 88384 times.
✓ Branch 3 taken 15111731 times.
15201989 if(showhero && is_cave_walking)
4729 {
4730 88384 hero_draw_done = true;
4731
3/4
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53632 times.
✓ Branch 3 taken 34752 times.
88384 if(Hero.getAction()==climbcovertop)
4732 {
4733 34752 cmby2=16;
4734 34752 }
4735
2/4
✓ Branch 0 taken 53632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53632 times.
53632 else if(Hero.getAction()==climbcoverbottom)
4736 {
4737 53632 cmby2=-16;
4738 53632 }
4739
4740
1/2
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
88384 decorations.draw2(scrollbuf,true);
4741
1/2
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
88384 Hero.draw(scrollbuf);
4742
1/2
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
88384 decorations.draw(scrollbuf,true);
4743
2/4
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
88384 int32_t ccx = (int32_t)Hero.getClimbCoverX();
4744
2/4
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
88384 int32_t ccy = (int32_t)Hero.getClimbCoverY();
4745
4746
3/6
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88384 times.
✗ Branch 5 not taken.
88384 overcombo(scrollbuf,ccx-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy+cmby2),MAPCSET(ccx,ccy+cmby2));
4747
3/6
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88384 times.
✗ Branch 5 not taken.
88384 putcombo(scrollbuf,ccx-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy),MAPCSET(ccx,ccy));
4748
4749
4/6
✓ Branch 0 taken 88384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88384 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15232 times.
✓ Branch 5 taken 73152 times.
88384 if(int32_t(Hero.getX())&15)
4750 {
4751
3/6
✓ Branch 0 taken 15232 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15232 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15232 times.
✗ Branch 5 not taken.
15232 overcombo(scrollbuf,ccx+16-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy+cmby2),MAPCSET(ccx+16,ccy+cmby2));
4752
3/6
✓ Branch 0 taken 15232 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15232 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15232 times.
✗ Branch 5 not taken.
15232 putcombo(scrollbuf,ccx+16-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy),MAPCSET(ccx+16,ccy));
4753 15232 }
4754 88384 }
4755 15201989 }
4756
4757
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 15545248 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
15545248 if (get_qr(qr_HERO_DIVE_UNDER_LAYER_1) && Hero.isDiving())
4758 {
4759 Hero.draw_under(scrollbuf);
4760 decorations.draw2(scrollbuf,true);
4761 Hero.draw(scrollbuf);
4762 decorations.draw(scrollbuf,true);
4763 hero_draw_done = true;
4764 }
4765
4766
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4767 15681566 do_layer(scrollbuf, 0, screen_handles[1], offx, offy); // LAYER 1
4768 15681566 });
4769
4770
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 do_layer_primitives(scrollbuf, 1);
4771
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 particles.draw(scrollbuf, true, 1);
4772
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(scrollbuf, 1);
4773
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 draw_msgstr(1, scrollbuf);
4774
4775 // Handle layer 2 NOT being used as background layers.
4776
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4777 15681566 mapscr* base_scr = screen_handles[0].base_scr;
4778
2/2
✓ Branch 0 taken 127281 times.
✓ Branch 1 taken 15554285 times.
15681566 if (!XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4779 15554285 do_layer(scrollbuf, 0, screen_handles[2], offx, offy);
4780 15681566 });
4781
4782
2/2
✓ Branch 0 taken 15417967 times.
✓ Branch 1 taken 127281 times.
15545248 if(!XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4783 {
4784
1/2
✓ Branch 0 taken 15417967 times.
✗ Branch 1 not taken.
15417967 do_layer_primitives(scrollbuf, 2);
4785
1/2
✓ Branch 0 taken 15417967 times.
✗ Branch 1 not taken.
15417967 particles.draw(scrollbuf, true, 2);
4786 15417967 }
4787
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(scrollbuf, 2);
4788
2/2
✓ Branch 0 taken 15417967 times.
✓ Branch 1 taken 127281 times.
15545248 if(!XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4789
1/2
✓ Branch 0 taken 15417967 times.
✗ Branch 1 not taken.
15417967 draw_msgstr(2, scrollbuf);
4790
4791
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 do_primitives(scrollbuf, SPLAYER_FFC_DRAW);
4792
4793
2/2
✓ Branch 0 taken 15201989 times.
✓ Branch 1 taken 343259 times.
15545248 if(get_qr(qr_LAYER12UNDERCAVE))
4794 {
4795
2/4
✓ Branch 0 taken 343259 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 343259 times.
343259 if(showhero && is_cave_walking)
4796 {
4797 hero_draw_done = true;
4798 if(Hero.getAction()==climbcovertop)
4799 {
4800 cmby2=16;
4801 }
4802 else if(Hero.getAction()==climbcoverbottom)
4803 {
4804 cmby2=-16;
4805 }
4806
4807 decorations.draw2(scrollbuf,true);
4808 Hero.draw(scrollbuf);
4809 decorations.draw(scrollbuf,true);
4810 int32_t ccx = (int32_t)(Hero.getClimbCoverX());
4811 int32_t ccy = (int32_t)(Hero.getClimbCoverY());
4812
4813 overcombo(scrollbuf,ccx-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy+cmby2),MAPCSET(ccx,ccy+cmby2));
4814 putcombo(scrollbuf,ccx-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy),MAPCSET(ccx,ccy));
4815
4816 if(int32_t(Hero.getX())&15)
4817 {
4818 overcombo(scrollbuf,ccx+16-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy+cmby2),MAPCSET(ccx+16,ccy+cmby2));
4819 putcombo(scrollbuf,ccx+16-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy),MAPCSET(ccx+16,ccy));
4820 }
4821 }
4822 343259 }
4823
4824
2/2
✓ Branch 0 taken 466049 times.
✓ Branch 1 taken 15079199 times.
15545248 if (get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4825 {
4826
1/2
✓ Branch 0 taken 15079199 times.
✗ Branch 1 not taken.
30294716 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4827 15215517 do_layer(scrollbuf, -2, screen_handles[0], offx, offy); // push blocks!
4828
2/2
✓ Branch 0 taken 14478915 times.
✓ Branch 1 taken 736602 times.
15215517 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
4829 {
4830 736602 do_layer(scrollbuf, -2, screen_handles[1], offx, offy); // push blocks!
4831 736602 do_layer(scrollbuf, -2, screen_handles[2], offx, offy); // push blocks!
4832 736602 }
4833 15215517 });
4834
4835
1/2
✓ Branch 0 taken 15079199 times.
✗ Branch 1 not taken.
15079199 do_primitives(scrollbuf, SPLAYER_PUSHBLOCK);
4836 15079199 }
4837
4838 // Show walkflags cheat
4839
2/4
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15545248 times.
15545248 if (show_walkflags || show_effectflags)
4840 {
4841 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4842 do_walkflags(screen_handles, offx, offy);
4843 do_effectflags(screen_handles[0].base_scr, offx, offy);
4844 });
4845
4846 do_walkflags(0, 0);
4847 }
4848
4849
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 putscrdoors(nearby_screens, scrollbuf, 0, playing_field_offset);
4850
4851 // Lens hints, doors etc.
4852
4/8
✓ Branch 0 taken 15535219 times.
✓ Branch 1 taken 10029 times.
✓ Branch 2 taken 15535219 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15535219 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
15545248 if(lensclk || (get_debug() && zc_getkey(KEY_L)))
4853 {
4854
2/2
✓ Branch 0 taken 4153 times.
✓ Branch 1 taken 5876 times.
10029 if(get_qr(qr_OLDLENSORDER))
4855 {
4856
1/2
✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
4153 draw_lens_under(scrollbuf, false);
4857
1/2
✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
4153 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_1);
4858 4153 }
4859
4860
1/2
✓ Branch 0 taken 10029 times.
✗ Branch 1 not taken.
10029 draw_lens_under(scrollbuf, true);
4861
1/2
✓ Branch 0 taken 10029 times.
✗ Branch 1 not taken.
10029 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_2);
4862 10029 }
4863
4864 // Blit those layers onto framebuf
4865
4866
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 set_draw_screen_clip(framebuf);
4867
4868
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 blit(scrollbuf, framebuf, 0, 0, 0, 0, 256, 232);
4869
4870 // After this point, scrollbuf is no longer drawn to - so things like dosubscr have access to a "partially rendered" frame.
4871 // I think only used for COOLSCROLL==0? Seems like a silly feature...
4872
4873 // Draw the subscreen, without clipping
4874
2/2
✓ Branch 0 taken 9251384 times.
✓ Branch 1 taken 6293864 times.
15545248 if(!get_qr(qr_SUBSCREENOVERSPRITES))
4875 {
4876 9251384 bool dotime = false;
4877
4/6
✓ Branch 0 taken 9251384 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3412853 times.
✓ Branch 3 taken 5838531 times.
✓ Branch 4 taken 3412853 times.
✗ Branch 5 not taken.
9251384 if (replay_version_check(22)) dotime = game->should_show_time();
4878
1/2
✓ Branch 0 taken 9251384 times.
✗ Branch 1 not taken.
9251384 put_passive_subscr(framebuf, 0, 0, dotime, sspUP);
4879 9251384 }
4880
4881 // Draw some sprites onto framebuf
4882
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 set_clip_rect(framebuf,0,0,256,232);
4883
4884
2/2
✓ Branch 0 taken 99496 times.
✓ Branch 1 taken 15445752 times.
15545248 if(!(pricesdisplaybuf->clip))
4885 {
4886
1/2
✓ Branch 0 taken 99496 times.
✗ Branch 1 not taken.
99496 masked_blit(pricesdisplaybuf,framebuf,0,0,0,playing_field_offset,256,176);
4887 99496 }
4888
4889
5/6
✓ Branch 0 taken 15499622 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15493294 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15545248 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4890 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4891
4892
4/4
✓ Branch 0 taken 15543374 times.
✓ Branch 1 taken 1874 times.
✓ Branch 2 taken 15454990 times.
✓ Branch 3 taken 88384 times.
15545248 if(showhero && !hero_draw_done)
4893 {
4894
1/2
✓ Branch 0 taken 15454990 times.
✗ Branch 1 not taken.
15454990 Hero.draw_under(framebuf);
4895
4896
3/4
✓ Branch 0 taken 15454990 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 141385 times.
✓ Branch 3 taken 15313605 times.
15454990 if(Hero.isSwimming())
4897 {
4898
1/2
✓ Branch 0 taken 141385 times.
✗ Branch 1 not taken.
141385 decorations.draw2(framebuf,true);
4899
1/2
✓ Branch 0 taken 141385 times.
✗ Branch 1 not taken.
141385 Hero.draw(framebuf);
4900
1/2
✓ Branch 0 taken 141385 times.
✗ Branch 1 not taken.
141385 decorations.draw(framebuf,true);
4901 141385 hero_draw_done = true;
4902 141385 }
4903 15454990 }
4904
4905 15545248 set<sprite*, SpriteSorter> sorted_sprites;
4906 15545248 vector<sprite*> temp_sprites;
4907 15545248 std::function<bool(sprite&)> add_sprite = [&](sprite& spr)
4908 {
4909 sorted_sprites.insert(&spr);
4910 return false;
4911 };
4912
4913
2/2
✓ Branch 0 taken 15542318 times.
✓ Branch 1 taken 2930 times.
15545248 if (classic_draw)
4914 {
4915
2/2
✓ Branch 0 taken 26095 times.
✓ Branch 1 taken 15516223 times.
15542318 if(drawguys)
4916 {
4917
4/4
✓ Branch 0 taken 1982674 times.
✓ Branch 1 taken 13533549 times.
✓ Branch 2 taken 991089 times.
✓ Branch 3 taken 991585 times.
15516223 if(get_qr(qr_NOFLICKER) || (frame&1))
4918 {
4919 // Just clips sprites if in a repeating, smooth maze.
4920
2/2
✓ Branch 0 taken 14515424 times.
✓ Branch 1 taken 9214 times.
14524638 bool do_clip = maze_state.active && maze_state.loopy;
4921
4922
1/2
✓ Branch 0 taken 14524638 times.
✗ Branch 1 not taken.
14524638 if(!get_qr(qr_OLD_WEAPON_DRAW_ANIMATE_TIMING))
4923 {
4924 if (do_clip)
4925 {
4926 Ewpns.drawshadow_smooth_maze(framebuf,get_qr(qr_TRANSSHADOWS));
4927 Lwpns.drawshadow_smooth_maze(framebuf,get_qr(qr_TRANSSHADOWS));
4928 }
4929 else
4930 {
4931 Ewpns.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS),true);
4932 Lwpns.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS),true);
4933 }
4934 }
4935
3/4
✓ Branch 0 taken 23629882 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9105244 times.
✓ Branch 3 taken 14524638 times.
23629882 for(int32_t i=0; i<Ewpns.Count(); i++)
4936 {
4937
3/4
✓ Branch 0 taken 9105244 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 197943 times.
✓ Branch 3 taken 8907301 times.
9105244 if(((weapon *)Ewpns.spr(i))->behind)
4938
2/4
✓ Branch 0 taken 197943 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 197943 times.
✗ Branch 3 not taken.
197943 Ewpns.spr(i)->draw(framebuf);
4939 9105244 }
4940
1/2
✓ Branch 0 taken 14524638 times.
✗ Branch 1 not taken.
14524638 do_primitives(framebuf, SPLAYER_EWEAP_BEHIND_DRAW);
4941
4942
3/4
✓ Branch 0 taken 19199747 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4675109 times.
✓ Branch 3 taken 14524638 times.
19199747 for(int32_t i=0; i<Lwpns.Count(); i++)
4943 {
4944
3/4
✓ Branch 0 taken 4675109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3205 times.
✓ Branch 3 taken 4671904 times.
4675109 if(((weapon *)Lwpns.spr(i))->behind)
4945
2/4
✓ Branch 0 taken 3205 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3205 times.
✗ Branch 3 not taken.
3205 Lwpns.spr(i)->draw(framebuf);
4946 4675109 }
4947
1/2
✓ Branch 0 taken 14524638 times.
✗ Branch 1 not taken.
14524638 do_primitives(framebuf, SPLAYER_LWEAP_BEHIND_DRAW);
4948
4949
6/6
✓ Branch 0 taken 9787774 times.
✓ Branch 1 taken 4736864 times.
✓ Branch 2 taken 1348300 times.
✓ Branch 3 taken 8439474 times.
✓ Branch 4 taken 674011 times.
✓ Branch 5 taken 674289 times.
14524638 if(get_qr(qr_SHADOWS)&&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4950 {
4951
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 9109827 times.
9113485 if (do_clip)
4952
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 guys.drawshadow_smooth_maze(framebuf,get_qr(qr_TRANSSHADOWS)!=0);
4953 else
4954
1/2
✓ Branch 0 taken 9109827 times.
✗ Branch 1 not taken.
9109827 guys.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0,true);
4955 9113485 }
4956
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14520980 times.
14524638 if (do_clip)
4957
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 guys.draw_smooth_maze(framebuf);
4958 else
4959
1/2
✓ Branch 0 taken 14520980 times.
✗ Branch 1 not taken.
14520980 guys.draw(framebuf,true);
4960
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14520980 times.
14524638 if (do_clip)
4961 {
4962 3658 int maze_screen = maze_state.scr->screen;
4963
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 auto [sx, sy] = translate_screen_coordinates_to_world(maze_screen);
4964
5/10
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3658 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3658 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3658 times.
✗ Branch 9 not taken.
18290 set_clip_rect(framebuf, sx - viewport.x, sy - viewport.y, sx + 256 - viewport.x, sy + 176 - viewport.y);
4965 3658 }
4966
1/2
✓ Branch 0 taken 14524638 times.
✗ Branch 1 not taken.
14524638 do_primitives(framebuf, SPLAYER_NPC_DRAW);
4967
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14520980 times.
14524638 if (do_clip)
4968
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 clear_clip_rect(framebuf);
4969
4970
1/2
✓ Branch 0 taken 14524638 times.
✗ Branch 1 not taken.
14524638 chainlinks.draw(framebuf,true);
4971
1/2
✓ Branch 0 taken 14524638 times.
✗ Branch 1 not taken.
14524638 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4972 //Lwpns.draw(framebuf,true);
4973
4974
3/4
✓ Branch 0 taken 23629882 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9105244 times.
✓ Branch 3 taken 14524638 times.
23629882 for(int32_t i=0; i<Ewpns.Count(); i++)
4975 {
4976
3/4
✓ Branch 0 taken 9105244 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8907301 times.
✓ Branch 3 taken 197943 times.
9105244 if(!((weapon *)Ewpns.spr(i))->behind)
4977
2/4
✓ Branch 0 taken 8907301 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8907301 times.
✗ Branch 3 not taken.
8907301 Ewpns.spr(i)->draw(framebuf);
4978 9105244 }
4979
1/2
✓ Branch 0 taken 14524638 times.
✗ Branch 1 not taken.
14524638 do_primitives(framebuf, SPLAYER_EWEAP_FRONT_DRAW);
4980
4981
3/4
✓ Branch 0 taken 19199747 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4675109 times.
✓ Branch 3 taken 14524638 times.
19199747 for(int32_t i=0; i<Lwpns.Count(); i++)
4982 {
4983
3/4
✓ Branch 0 taken 4675109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4671904 times.
✓ Branch 3 taken 3205 times.
4675109 if(!((weapon *)Lwpns.spr(i))->behind)
4984
2/4
✓ Branch 0 taken 4671904 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4671904 times.
✗ Branch 3 not taken.
4671904 Lwpns.spr(i)->draw(framebuf);
4985 4675109 }
4986
1/2
✓ Branch 0 taken 14524638 times.
✗ Branch 1 not taken.
14524638 do_primitives(framebuf, SPLAYER_LWEAP_FRONT_DRAW);
4987
4988
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14520980 times.
14524638 if (do_clip)
4989
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 items.draw_smooth_maze(framebuf);
4990 else
4991
1/2
✓ Branch 0 taken 14520980 times.
✗ Branch 1 not taken.
14520980 items.draw(framebuf,true);
4992
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14520980 times.
14524638 if (do_clip)
4993 {
4994 3658 int maze_screen = maze_state.scr->screen;
4995
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 auto [sx, sy] = translate_screen_coordinates_to_world(maze_screen);
4996
5/10
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3658 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3658 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3658 times.
✗ Branch 9 not taken.
18290 set_clip_rect(framebuf, sx - viewport.x, sy - viewport.y, sx + 256 - viewport.x, sy + 176 - viewport.y);
4997 3658 }
4998
1/2
✓ Branch 0 taken 14524638 times.
✗ Branch 1 not taken.
14524638 do_primitives(framebuf, SPLAYER_ITEMSPRITE_DRAW);
4999
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14520980 times.
14524638 if (do_clip)
5000
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 clear_clip_rect(framebuf);
5001 14524638 }
5002 else
5003 {
5004
3/4
✓ Branch 0 taken 1496957 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 505372 times.
✓ Branch 3 taken 991585 times.
1496957 for(int32_t i=0; i<Ewpns.Count(); i++)
5005 {
5006
3/4
✓ Branch 0 taken 505372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8645 times.
✓ Branch 3 taken 496727 times.
505372 if(((weapon *)Ewpns.spr(i))->behind)
5007
2/4
✓ Branch 0 taken 8645 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8645 times.
✗ Branch 3 not taken.
8645 Ewpns.spr(i)->draw(framebuf);
5008 505372 }
5009
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 do_primitives(framebuf, SPLAYER_EWEAP_BEHIND_DRAW);
5010
5011
3/4
✓ Branch 0 taken 1222731 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 231146 times.
✓ Branch 3 taken 991585 times.
1222731 for(int32_t i=0; i<Lwpns.Count(); i++)
5012 {
5013
2/4
✓ Branch 0 taken 231146 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 231146 times.
231146 if(((weapon *)Lwpns.spr(i))->behind)
5014 Lwpns.spr(i)->draw(framebuf);
5015 231146 }
5016
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 do_primitives(framebuf, SPLAYER_LWEAP_BEHIND_DRAW);
5017
5018
3/4
✓ Branch 0 taken 228620 times.
✓ Branch 1 taken 762965 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 228620 times.
991585 if(get_qr(qr_SHADOWS)&&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
5019 {
5020
1/2
✓ Branch 0 taken 228620 times.
✗ Branch 1 not taken.
228620 guys.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0,true);
5021 228620 }
5022
5023
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 items.draw(framebuf,false);
5024
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 do_primitives(framebuf, SPLAYER_ITEMSPRITE_DRAW);
5025
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 chainlinks.draw(framebuf,false);
5026
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
5027 //Lwpns.draw(framebuf,false);
5028
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 guys.draw(framebuf,false);
5029
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 do_primitives(framebuf, SPLAYER_NPC_DRAW);
5030
5031
3/4
✓ Branch 0 taken 1496957 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 505372 times.
✓ Branch 3 taken 991585 times.
1496957 for(int32_t i=0; i<Ewpns.Count(); i++)
5032 {
5033
3/4
✓ Branch 0 taken 505372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 496727 times.
✓ Branch 3 taken 8645 times.
505372 if(!((weapon *)Ewpns.spr(i))->behind)
5034 {
5035
2/4
✓ Branch 0 taken 496727 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 496727 times.
✗ Branch 3 not taken.
496727 Ewpns.spr(i)->draw(framebuf);
5036 496727 }
5037 505372 }
5038
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 do_primitives(framebuf, SPLAYER_EWEAP_FRONT_DRAW);
5039
5040
3/4
✓ Branch 0 taken 1222731 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 231146 times.
✓ Branch 3 taken 991585 times.
1222731 for(int32_t i=0; i<Lwpns.Count(); i++)
5041 {
5042
2/4
✓ Branch 0 taken 231146 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 231146 times.
✗ Branch 3 not taken.
231146 if(!((weapon *)Lwpns.spr(i))->behind)
5043 {
5044
2/4
✓ Branch 0 taken 231146 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 231146 times.
✗ Branch 3 not taken.
231146 Lwpns.spr(i)->draw(framebuf);
5045 231146 }
5046 231146 }
5047
1/2
✓ Branch 0 taken 991585 times.
✗ Branch 1 not taken.
991585 do_primitives(framebuf, SPLAYER_LWEAP_FRONT_DRAW);
5048 }
5049
5050
1/2
✓ Branch 0 taken 15516223 times.
✗ Branch 1 not taken.
15516223 guys.draw2(framebuf,true);
5051 15516223 }
5052
5053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15542318 times.
15542318 if(mirror_portal.destdmap > -1)
5054 mirror_portal.draw(framebuf);
5055
1/2
✓ Branch 0 taken 15542318 times.
✗ Branch 1 not taken.
15542318 portals.draw(framebuf,true);
5056
5057
4/4
✓ Branch 0 taken 15540444 times.
✓ Branch 1 taken 1874 times.
✓ Branch 2 taken 88384 times.
✓ Branch 3 taken 15452060 times.
15542318 if(showhero && !is_cave_walking)
5058 {
5059
2/2
✓ Branch 0 taken 14992427 times.
✓ Branch 1 taken 459633 times.
15452060 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
5060 {
5061
1/2
✓ Branch 0 taken 14992427 times.
✗ Branch 1 not taken.
14992427 mblock2.draw(framebuf,-1);
5062
1/2
✓ Branch 0 taken 14992427 times.
✗ Branch 1 not taken.
14992427 do_primitives(framebuf, SPLAYER_MOVINGBLOCK);
5063 14992427 }
5064
2/2
✓ Branch 0 taken 15310675 times.
✓ Branch 1 taken 141385 times.
15452060 if(!hero_draw_done)
5065 {
5066
8/12
✓ Branch 0 taken 15310675 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15310675 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15291505 times.
✓ Branch 5 taken 19170 times.
✓ Branch 6 taken 15291505 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15291505 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1370 times.
✓ Branch 11 taken 15309305 times.
15310675 if((Hero.getZ()>0 || Hero.getFakeZ()>0) &&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
5067 {
5068
2/2
✓ Branch 0 taken 18485 times.
✓ Branch 1 taken 15292190 times.
15310675 Hero.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0);
5069 18485 }
5070
5071
6/8
✓ Branch 0 taken 15310675 times.
✓ Branch 1 taken 15292190 times.
✓ Branch 2 taken 15310675 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15310675 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 15296611 times.
✓ Branch 7 taken 14064 times.
18485 if(Hero.getZ() <= (zfix)zinit.jump_hero_layer_threshold)
5072 {
5073
1/2
✓ Branch 0 taken 15296611 times.
✗ Branch 1 not taken.
15296611 decorations.draw2(framebuf,true);
5074
1/2
✓ Branch 0 taken 15296611 times.
✗ Branch 1 not taken.
15296611 Hero.draw(framebuf);
5075
1/2
✓ Branch 0 taken 15296611 times.
✗ Branch 1 not taken.
15296611 decorations.draw(framebuf,true);
5076 15296611 hero_draw_done = true;
5077 15296611 }
5078 15310675 }
5079 15452060 }
5080
5081
3/4
✓ Branch 0 taken 54882771 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39340453 times.
✓ Branch 3 taken 15542318 times.
54882771 for(int32_t i=0; i<guys.Count(); i++)
5082 {
5083
3/4
✓ Branch 0 taken 39340453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15945464 times.
✓ Branch 3 taken 23394989 times.
39340453 if(((enemy*)guys.spr(i))->type == eeWALK)
5084 {
5085
3/4
✓ Branch 0 taken 15945464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7295 times.
✓ Branch 3 taken 15938169 times.
15945464 if(((eStalfos*)guys.spr(i))->hashero)
5086 {
5087
2/4
✓ Branch 0 taken 7295 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7295 times.
✗ Branch 3 not taken.
7295 guys.spr(i)->draw(framebuf);
5088 7295 }
5089 15945464 }
5090
5091
3/4
✓ Branch 0 taken 39340453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 507162 times.
✓ Branch 3 taken 38833291 times.
39340453 if(((enemy*)guys.spr(i))->type == eeWALLM)
5092 {
5093
3/4
✓ Branch 0 taken 507162 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1329 times.
✓ Branch 3 taken 505833 times.
507162 if(((eWallM*)guys.spr(i))->hashero)
5094 {
5095
2/4
✓ Branch 0 taken 1329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1329 times.
✗ Branch 3 not taken.
1329 guys.spr(i)->draw(framebuf);
5096 1329 }
5097 507162 }
5098
5099
11/20
✓ Branch 0 taken 39340453 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39340453 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39340453 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 39340453 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 39340453 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 39340453 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 39340453 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 39340453 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 39340453 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1342694 times.
✓ Branch 19 taken 37997759 times.
39340453 if(guys.spr(i)->z+guys.spr(i)->fakez > Hero.getZ()+Hero.getFakeZ())
5100 {
5101 //Jumping enemies in front of Hero.
5102
2/4
✓ Branch 0 taken 1342694 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1342694 times.
✗ Branch 3 not taken.
1342694 guys.spr(i)->draw(framebuf);
5103 1342694 }
5104
1/2
✓ Branch 0 taken 39340453 times.
✗ Branch 1 not taken.
39340453 do_primitives(framebuf, SPLAYER_NPC_ABOVEPLAYER_DRAW);
5105 39340453 }
5106 15542318 }
5107 else
5108 {
5109
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 if(drawguys)
5110 {
5111
2/4
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2930 times.
✗ Branch 3 not taken.
2930 chainlinks.forEach(add_sprite);
5112
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2930 times.
✓ Branch 2 taken 2930 times.
✗ Branch 3 not taken.
5860 bool show_enemy_shadows = (get_qr(qr_SHADOWS)&&(!get_qr(qr_SHADOWSFLICKER)||frame&1));
5113 25837 auto add_spr_shadow = [&](sprite& spr)
5114 {
5115 22907 sorted_sprites.insert(&spr);
5116
3/4
✓ Branch 0 taken 1291 times.
✓ Branch 1 taken 21616 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1291 times.
22907 if(spr.total_z() > 0 && spr.can_drawshadow())
5117 {
5118
1/2
✓ Branch 0 taken 1291 times.
✗ Branch 1 not taken.
1291 tempsprite_shadow* shadow = new tempsprite_shadow(&spr);
5119 1291 sorted_sprites.insert(shadow);
5120 1291 temp_sprites.push_back(shadow);
5121 1291 }
5122 22907 return false;
5123 };
5124
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 Lwpns.forEach(add_spr_shadow);
5125
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 Ewpns.forEach(add_spr_shadow);
5126
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 items.forEach(add_spr_shadow);
5127
4/14
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2930 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2930 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2930 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
2930 guys.forEach(show_enemy_shadows ? add_spr_shadow : add_sprite);
5128 2930 }
5129
2/4
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2930 times.
✗ Branch 3 not taken.
2930 if(showhero && !hero_draw_done)
5130 {
5131
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 sorted_sprites.insert(&Hero);
5132
9/14
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2930 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2290 times.
✓ Branch 5 taken 640 times.
✓ Branch 6 taken 2290 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2290 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 2930 times.
✓ Branch 12 taken 2290 times.
✓ Branch 13 taken 2290 times.
2930 if((Hero.getZ()>0 || Hero.getFakeZ()>0) &&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
5133 {
5134
3/4
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 4580 times.
✓ Branch 2 taken 640 times.
✗ Branch 3 not taken.
5220 tempsprite_shadow* shadow = new tempsprite_shadow(&Hero);
5135
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 sorted_sprites.insert(shadow);
5136
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 temp_sprites.push_back(shadow);
5137 640 }
5138 2930 }
5139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2930 times.
2930 if(mirror_portal.destdmap > -1)
5140 sorted_sprites.insert(&mirror_portal);
5141
2/4
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2930 times.
✗ Branch 3 not taken.
2930 portals.forEach(add_sprite);
5142
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
5143
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 sorted_sprites.insert(&mblock2);
5144 }
5145 15545248 auto sprite_it = sorted_sprites.begin();
5146
2/2
✓ Branch 0 taken 2930 times.
✓ Branch 1 taken 15542318 times.
15545248 if (!classic_draw)
5147
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 draw_sprites(framebuf, sorted_sprites, sprite_it, zinit.sprite_z_thresholds[SPRITE_THRESHOLD_GROUND]);
5148
5149 // Draw some layers onto framebuf
5150
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 set_draw_screen_clip(framebuf);
5151
5/6
✓ Branch 0 taken 15499622 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15493294 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15545248 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
5152 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5153
5154 // Handle layer 3 NOT being used as background layers.
5155
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5156 15681566 mapscr* base_scr = screen_handles[0].base_scr;
5157
2/2
✓ Branch 0 taken 92659 times.
✓ Branch 1 taken 15588907 times.
15681566 if (!XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
5158 15588907 do_layer(framebuf, 0, screen_handles[3], offx, offy);
5159 15681566 });
5160
5161
2/2
✓ Branch 0 taken 2930 times.
✓ Branch 1 taken 15542318 times.
15545248 if (!classic_draw)
5162
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 draw_sprites(framebuf, sorted_sprites, sprite_it, zinit.sprite_z_thresholds[SPRITE_THRESHOLD_3]);
5163
5164
2/2
✓ Branch 0 taken 15452589 times.
✓ Branch 1 taken 92659 times.
15545248 if(!XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
5165 {
5166
1/2
✓ Branch 0 taken 15452589 times.
✗ Branch 1 not taken.
15452589 do_layer_primitives(framebuf, 3);
5167
1/2
✓ Branch 0 taken 15452589 times.
✗ Branch 1 not taken.
15452589 particles.draw(framebuf, true, 3);
5168 15452589 }
5169
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(framebuf, 3);
5170
2/2
✓ Branch 0 taken 15452589 times.
✓ Branch 1 taken 92659 times.
15545248 if(!XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
5171
1/2
✓ Branch 0 taken 15452589 times.
✗ Branch 1 not taken.
15452589 draw_msgstr(3);
5172
5173
5174
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5175 15681566 do_layer(framebuf, 0, screen_handles[4], offx, offy);
5176 15681566 });
5177
5178
2/2
✓ Branch 0 taken 2930 times.
✓ Branch 1 taken 15542318 times.
15545248 if (!classic_draw)
5179
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 draw_sprites(framebuf, sorted_sprites, sprite_it, zinit.sprite_z_thresholds[SPRITE_THRESHOLD_4]);
5180
5181
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 do_layer_primitives(framebuf, 4);
5182
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 particles.draw(framebuf, true, 4);
5183
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(framebuf, 4);
5184
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 draw_msgstr(4);
5185
5186
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5187 15681566 do_layer(framebuf, -1, screen_handles[0], offx, offy);
5188
2/2
✓ Branch 0 taken 14402748 times.
✓ Branch 1 taken 1278818 times.
15681566 if (get_qr(qr_OVERHEAD_COMBOS_L1_L2))
5189 {
5190 1278818 do_layer(framebuf, -1, screen_handles[1], offx, offy);
5191 1278818 do_layer(framebuf, -1, screen_handles[2], offx, offy);
5192 1278818 }
5193 15681566 });
5194
5195
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 do_primitives(framebuf, SPLAYER_OVERHEAD_CMB);
5196
5197 // Draw some flying sprites onto framebuf
5198
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 clear_clip_rect(framebuf);
5199
5/6
✓ Branch 0 taken 15499622 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15493294 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15545248 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
5200 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5201
5202
2/2
✓ Branch 0 taken 15542318 times.
✓ Branch 1 taken 2930 times.
15545248 if (classic_draw)
5203 {
5204 //Jumping Hero and jumping enemies are drawn on this layer.
5205
5/8
✓ Branch 0 taken 15542318 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15542318 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15542318 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14064 times.
✓ Branch 7 taken 15528254 times.
15542318 if(Hero.getZ() > (zfix)zinit.jump_hero_layer_threshold)
5206 {
5207
1/2
✓ Branch 0 taken 14064 times.
✗ Branch 1 not taken.
14064 decorations.draw2(framebuf,false);
5208
1/2
✓ Branch 0 taken 14064 times.
✗ Branch 1 not taken.
14064 Hero.draw(framebuf);
5209
1/2
✓ Branch 0 taken 14064 times.
✗ Branch 1 not taken.
14064 chainlinks.draw(framebuf,true);
5210
1/2
✓ Branch 0 taken 14064 times.
✗ Branch 1 not taken.
14064 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
5211
5212
3/4
✓ Branch 0 taken 16806 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2742 times.
✓ Branch 3 taken 14064 times.
16806 for(int32_t i=0; i<Lwpns.Count(); i++)
5213 {
5214
9/16
✓ Branch 0 taken 2742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2742 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2742 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2742 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2742 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2742 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2742 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 239 times.
✓ Branch 15 taken 2503 times.
2742 if(Lwpns.spr(i)->z+Lwpns.spr(i)->fakez > (zfix)zinit.jump_hero_layer_threshold)
5215 {
5216
2/4
✓ Branch 0 taken 239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 239 times.
✗ Branch 3 not taken.
239 Lwpns.spr(i)->draw(framebuf);
5217 239 }
5218 2742 }
5219
1/2
✓ Branch 0 taken 14064 times.
✗ Branch 1 not taken.
14064 do_primitives(framebuf, SPLAYER_LWEAP_ABOVE_DRAW);
5220
5221
1/2
✓ Branch 0 taken 14064 times.
✗ Branch 1 not taken.
14064 decorations.draw(framebuf,false);
5222 14064 }
5223
5224
5/6
✓ Branch 0 taken 3288981 times.
✓ Branch 1 taken 12253337 times.
✓ Branch 2 taken 44336928 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32083591 times.
✓ Branch 5 taken 12253337 times.
47625909 if(!get_qr(qr_ENEMIESZAXIS)) for(int32_t i=0; i<guys.Count(); i++)
5225 {
5226
13/22
✓ Branch 0 taken 32083591 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32083591 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27177493 times.
✓ Branch 5 taken 4906098 times.
✓ Branch 6 taken 27177493 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 27177493 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27177493 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27177493 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 27177493 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 27177493 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 27177493 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 6568 times.
✓ Branch 21 taken 27170925 times.
32083591 if((isflier(guys.spr(i)->id)) || (guys.spr(i)->z+guys.spr(i)->fakez) > (zfix)zinit.jump_hero_layer_threshold)
5227 {
5228
2/4
✓ Branch 0 taken 4912666 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4912666 times.
✗ Branch 3 not taken.
4912666 guys.spr(i)->draw(framebuf);
5229 4912666 }
5230 44336928 }
5231 else
5232 {
5233
3/4
✓ Branch 0 taken 10545843 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7256862 times.
✓ Branch 3 taken 3288981 times.
10545843 for(int32_t i=0; i<guys.Count(); i++)
5234 {
5235
13/22
✓ Branch 0 taken 7256862 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7256862 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6081157 times.
✓ Branch 5 taken 1175705 times.
✓ Branch 6 taken 6081157 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6081157 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6081157 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5594346 times.
✓ Branch 13 taken 486811 times.
✓ Branch 14 taken 5594346 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5594346 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5594346 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5594346 times.
7256862 if((isflier(guys.spr(i)->id)) || guys.spr(i)->z > 0 || guys.spr(i)->fakez > 0)
5236 {
5237
2/4
✓ Branch 0 taken 1662516 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1662516 times.
✗ Branch 3 not taken.
1662516 guys.spr(i)->draw(framebuf);
5238 1662516 }
5239 7256862 }
5240 }
5241
1/2
✓ Branch 0 taken 15542318 times.
✗ Branch 1 not taken.
15542318 do_primitives(framebuf, SPLAYER_NPC_AIRBORNE_DRAW);
5242 15542318 }
5243
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 else draw_sprites(framebuf, sorted_sprites, sprite_it, zinit.sprite_z_thresholds[SPRITE_THRESHOLD_OVERHEAD]);
5244
5245 // Draw the Moving Fairy above layer 3
5246
3/4
✓ Branch 0 taken 18691634 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3146386 times.
✓ Branch 3 taken 15545248 times.
18691634 for(int32_t i=0; i<items.Count(); i++)
5247
6/8
✓ Branch 0 taken 3146386 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69867 times.
✓ Branch 3 taken 3076519 times.
✓ Branch 4 taken 69867 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 60153 times.
✓ Branch 7 taken 9714 times.
3206539 if(itemsbuf[items.spr(i)->id].type == itype_fairy && itemsbuf[items.spr(i)->id].misc3)
5248
2/4
✓ Branch 0 taken 60153 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 60153 times.
✗ Branch 3 not taken.
60153 items.spr(i)->draw(framebuf);
5249
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 do_primitives(framebuf, SPLAYER_FAIRYITEM_DRAW);
5250
5251 // Draw some layers onto framebuf
5252
5253
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 set_draw_screen_clip(framebuf);
5254
5255
2/2
✓ Branch 0 taken 15530896 times.
✓ Branch 1 taken 14352 times.
15545248 if (lightbeam_present)
5256 {
5257 14352 color_map = &trans_table2;
5258
2/2
✓ Branch 0 taken 13114 times.
✓ Branch 1 taken 1238 times.
14352 if(get_qr(qr_LIGHTBEAM_TRANSPARENT))
5259
1/2
✓ Branch 0 taken 13114 times.
✗ Branch 1 not taken.
13114 draw_trans_sprite(framebuf, lightbeam_bmp, 0, playing_field_offset);
5260 else
5261
1/2
✓ Branch 0 taken 1238 times.
✗ Branch 1 not taken.
1238 masked_blit(lightbeam_bmp, framebuf, 0, 0, 0, playing_field_offset, 256, 176);
5262 14352 color_map = &trans_table;
5263 14352 }
5264
5265
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5266 15681566 do_layer(framebuf, 0, screen_handles[5], offx, offy);
5267 15681566 });
5268
5269
2/2
✓ Branch 0 taken 2930 times.
✓ Branch 1 taken 15542318 times.
15545248 if (!classic_draw)
5270
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 draw_sprites(framebuf, sorted_sprites, sprite_it, zinit.sprite_z_thresholds[SPRITE_THRESHOLD_5]);
5271
5272
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 do_layer_primitives(framebuf, 5);
5273
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 particles.draw(framebuf, true, 5);
5274
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(framebuf, 5);
5275
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 draw_msgstr(5);
5276
5277
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(framebuf, -1000); // 'overhead' freeform combos
5278
5279
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 do_primitives(framebuf, SPLAYER_OVERHEAD_FFC);
5280
5281
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5282 15681566 do_layer(framebuf, 0, screen_handles[6], offx, offy);
5283 15681566 });
5284
5285
2/2
✓ Branch 0 taken 2930 times.
✓ Branch 1 taken 15542318 times.
15545248 if (!classic_draw)
5286
1/2
✓ Branch 0 taken 2930 times.
✗ Branch 1 not taken.
2930 draw_sprites(framebuf, sorted_sprites, sprite_it, word(-1));
5287
5288
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 do_layer_primitives(framebuf, 6);
5289
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 particles.draw(framebuf, true, 6);
5290
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(framebuf, 6);
5291
5292 15545248 bool any_dark = false;
5293
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5294 15681566 mapscr* base_scr = screen_handles[0].scr;
5295 15681566 any_dark |= is_dark(base_scr);
5296 15681566 });
5297
5298 // Handle low drawn darkness
5299
4/4
✓ Branch 0 taken 1275035 times.
✓ Branch 1 taken 14270213 times.
✓ Branch 2 taken 1031264 times.
✓ Branch 3 taken 243771 times.
15545248 if(get_qr(qr_NEW_DARKROOM) && any_dark)
5300 {
5301
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
493776 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5302 250005 mapscr* base_scr = screen_handles[0].scr;
5303 250005 calc_darkroom_combos(base_scr, offx, offy + playing_field_offset);
5304 250005 calc_darkroom_ffcs(base_scr, 0, playing_field_offset);
5305 250005 });
5306
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
243771 if(showhero)
5307
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
243771 Hero.calc_darkroom_hero(0, -playing_field_offset);
5308
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
493776 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5309 250005 mapscr* base_scr = screen_handles[0].scr;
5310
2/2
✓ Branch 0 taken 245275 times.
✓ Branch 1 taken 4730 times.
250005 if (!is_dark(base_scr))
5311 {
5312 4730 offy += playing_field_offset;
5313 4730 rectfill(darkscr_bmp, offx - viewport.x, offy - viewport.y, offx - viewport.x + 256 - 1, offy - viewport.y + 176 - 1, 0);
5314 4730 rectfill(darkscr_bmp_trans, offx - viewport.x, offy - viewport.y, offx - viewport.x + 256 - 1, offy - viewport.y + 176 - 1, 0);
5315 4730 }
5316 250005 });
5317 243771 }
5318
5319 //Darkroom if under the subscreen
5320
6/6
✓ Branch 0 taken 1275035 times.
✓ Branch 1 taken 14270213 times.
✓ Branch 2 taken 825837 times.
✓ Branch 3 taken 449198 times.
✓ Branch 4 taken 231780 times.
✓ Branch 5 taken 594057 times.
15545248 if(get_qr(qr_NEW_DARKROOM) && get_qr(qr_NEWDARK_L6) && any_dark)
5321 {
5322
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 do_primitives(framebuf, SPLAYER_DARKROOM_UNDER);
5323
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 set_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231780 times.
231780 if(hero_scr->flags9 & fDARK_DITHER) //dither the entire bitmap
5325 {
5326 ditherblit(darkscr_bmp,darkscr_bmp,0,game->get_dither_type(),game->get_dither_arg());
5327 ditherblit(darkscr_bmp_trans,darkscr_bmp_trans,0,game->get_dither_type(),game->get_dither_arg());
5328 }
5329
5330 231780 color_map = &trans_table2;
5331
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 231636 times.
231780 if(hero_scr->flags9 & fDARK_TRANS) //draw the dark as transparent
5332 {
5333
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 draw_trans_sprite(framebuf, darkscr_bmp, 0, 0);
5334
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(get_qr(qr_NEWDARK_TRANS_STACKING))
5335
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5336 144 }
5337 else
5338 {
5339
1/2
✓ Branch 0 taken 231636 times.
✗ Branch 1 not taken.
231636 masked_blit(darkscr_bmp, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
5340
1/2
✓ Branch 0 taken 231636 times.
✗ Branch 1 not taken.
231636 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5341 }
5342 231780 color_map = &trans_table;
5343
5344
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 set_clip_rect(framebuf, 0, 0, framebuf->w, framebuf->h);
5345
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 do_primitives(framebuf, SPLAYER_DARKROOM_OVER);
5346 231780 }
5347
5348
3/6
✓ Branch 0 taken 45626 times.
✓ Branch 1 taken 15499622 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45626 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
15545248 if (is_extended_height_mode() && lensclk && !FFCore.system_suspend[susptLENS])
5349 {
5350 draw_lens_over();
5351 --lensclk;
5352 }
5353
5354 // Draw some text on framebuf
5355
5356
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 set_clip_rect(framebuf,0,0,256,232);
5357
5358
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 if(!get_qr(qr_LAYER6_STRINGS_OVER_SUBSCREEN))
5359
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 draw_msgstr(6);
5360
5361 // Draw the subscreen, without clipping
5362
2/2
✓ Branch 0 taken 6293864 times.
✓ Branch 1 taken 9251384 times.
15545248 if(get_qr(qr_SUBSCREENOVERSPRITES))
5363 {
5364
2/4
✓ Branch 0 taken 6293864 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6293864 times.
✗ Branch 3 not taken.
6293864 put_passive_subscr(framebuf, 0, 0, game->should_show_time(), sspUP);
5365
1/2
✓ Branch 0 taken 6293864 times.
✗ Branch 1 not taken.
6293864 do_primitives(framebuf, 7);
5366 6293864 }
5367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9251384 times.
9251384 else if (!classic_draw)
5368 do_primitives(framebuf, 7);
5369
5370
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15545248 times.
15545248 if(get_qr(qr_LAYER6_STRINGS_OVER_SUBSCREEN))
5371 draw_msgstr(6);
5372
5373 // Handle high-drawn darkness
5374
6/6
✓ Branch 0 taken 1275035 times.
✓ Branch 1 taken 14270213 times.
✓ Branch 2 taken 449198 times.
✓ Branch 3 taken 825837 times.
✓ Branch 4 taken 11991 times.
✓ Branch 5 taken 437207 times.
15545248 if(get_qr(qr_NEW_DARKROOM) && !get_qr(qr_NEWDARK_L6) && any_dark)
5375 {
5376
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 do_primitives(framebuf, SPLAYER_DARKROOM_UNDER);
5377
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 set_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11991 times.
11991 if(hero_scr->flags9 & fDARK_DITHER) //dither the entire bitmap
5379 {
5380 ditherblit(darkscr_bmp,darkscr_bmp,0,game->get_dither_type(),game->get_dither_arg());
5381 ditherblit(darkscr_bmp_trans,darkscr_bmp_trans,0,game->get_dither_type(),game->get_dither_arg());
5382 }
5383
5384 11991 color_map = &trans_table2;
5385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11991 times.
11991 if(hero_scr->flags9 & fDARK_TRANS) //draw the dark as transparent
5386 {
5387 draw_trans_sprite(framebuf, darkscr_bmp, 0, 0);
5388 if(get_qr(qr_NEWDARK_TRANS_STACKING))
5389 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5390 }
5391 else
5392 {
5393
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 masked_blit(darkscr_bmp, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
5394
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5395 }
5396 11991 color_map = &trans_table;
5397
5398
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 set_clip_rect(framebuf, 0, 0, framebuf->w, framebuf->h);
5399
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 do_primitives(framebuf, SPLAYER_DARKROOM_OVER);
5400 11991 }
5401
5402
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 _do_current_ffc_layer(framebuf, 7);
5403
1/2
✓ Branch 0 taken 15545248 times.
✗ Branch 1 not taken.
15545248 draw_msgstr(7);
5404
5405
2/2
✓ Branch 0 taken 15043712 times.
✓ Branch 1 taken 30588960 times.
15545248 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
5406
3/4
✓ Branch 0 taken 14943451 times.
✓ Branch 1 taken 123511 times.
✓ Branch 2 taken 14943451 times.
✗ Branch 3 not taken.
15043712 if(runGeneric) FFCore.runGenericPassiveEngine(SCR_TIMING_POST_DRAW);
5407
5408
2/2
✓ Branch 0 taken 1931 times.
✓ Branch 1 taken 15066962 times.
15068893 for(sprite* spr : temp_sprites)
5409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1931 times.
1931 delete spr;
5410 76244882 }
5411
5412 // TODO: separate setting door data and drawing door
5413 28153 void put_door(mapscr* scr, BITMAP *dest, int32_t pos, int32_t side, int32_t type, bool redraw, bool even_walls)
5414 {
5415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28153 times.
28153 if (type > 8) return;
5416
5417 28153 int32_t d=scr->door_combo_set;
5418
5419
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15611 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12542 times.
28153 switch(type)
5420 {
5421 case dt_wall:
5422 case dt_walk:
5423 if(!even_walls)
5424 break;
5425 [[fallthrough]];
5426 case dt_pass:
5427
3/4
✓ Branch 0 taken 1036 times.
✓ Branch 1 taken 11506 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1036 times.
12542 if(!get_qr(qr_REPLACEOPENDOORS) && !even_walls)
5428 1036 break;
5429 [[fallthrough]];
5430 case dt_lock:
5431 case dt_shut:
5432 case dt_boss:
5433 case dt_olck:
5434 case dt_osht:
5435 case dt_obos:
5436 case dt_bomb:
5437
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 7259 times.
✓ Branch 2 taken 6784 times.
✓ Branch 3 taken 6362 times.
✓ Branch 4 taken 6712 times.
27117 switch(side)
5438 {
5439 case up:
5440 7259 scr->data[pos] = DoorComboSets[d].doorcombo_u[type][0];
5441 7259 scr->cset[pos] = DoorComboSets[d].doorcset_u[type][0];
5442 7259 scr->sflag[pos] = 0;
5443 7259 scr->data[pos+1] = DoorComboSets[d].doorcombo_u[type][1];
5444 7259 scr->cset[pos+1] = DoorComboSets[d].doorcset_u[type][1];
5445 7259 scr->sflag[pos+1] = 0;
5446 7259 scr->data[pos+16] = DoorComboSets[d].doorcombo_u[type][2];
5447 7259 scr->cset[pos+16] = DoorComboSets[d].doorcset_u[type][2];
5448 7259 scr->sflag[pos+16] = 0;
5449 7259 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_u[type][3];
5450 7259 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_u[type][3];
5451 7259 scr->sflag[pos+16+1] = 0;
5452
5453
2/2
✓ Branch 0 taken 5435 times.
✓ Branch 1 taken 1824 times.
7259 if(redraw)
5454 {
5455 3648 putcombo(dest,(pos&15)<<4,pos&0xF0,
5456 1824 DoorComboSets[d].doorcombo_u[type][0],
5457 1824 DoorComboSets[d].doorcset_u[type][0]);
5458 3648 putcombo(dest,((pos&15)<<4)+16,pos&0xF0,
5459 1824 DoorComboSets[d].doorcombo_u[type][1],
5460 1824 DoorComboSets[d].doorcset_u[type][1]);
5461 1824 }
5462
5463 7259 break;
5464
5465 case down:
5466 6784 scr->data[pos] = DoorComboSets[d].doorcombo_d[type][0];
5467 6784 scr->cset[pos] = DoorComboSets[d].doorcset_d[type][0];
5468 6784 scr->sflag[pos] = 0;
5469 6784 scr->data[pos+1] = DoorComboSets[d].doorcombo_d[type][1];
5470 6784 scr->cset[pos+1] = DoorComboSets[d].doorcset_d[type][1];
5471 6784 scr->sflag[pos+1] = 0;
5472 6784 scr->data[pos+16] = DoorComboSets[d].doorcombo_d[type][2];
5473 6784 scr->cset[pos+16] = DoorComboSets[d].doorcset_d[type][2];
5474 6784 scr->sflag[pos+16] = 0;
5475 6784 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_d[type][3];
5476 6784 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_d[type][3];
5477 6784 scr->sflag[pos+16+1] = 0;
5478
5479
2/2
✓ Branch 0 taken 5463 times.
✓ Branch 1 taken 1321 times.
6784 if(redraw)
5480 {
5481 2642 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5482 1321 DoorComboSets[d].doorcombo_d[type][2],
5483 1321 DoorComboSets[d].doorcset_d[type][2]);
5484 2642 putcombo(dest,((pos&15)<<4)+16,(pos&0xF0)+16,
5485 1321 DoorComboSets[d].doorcombo_d[type][3],
5486 1321 DoorComboSets[d].doorcset_d[type][3]);
5487 1321 }
5488
5489 6784 break;
5490
5491 case left:
5492 6362 scr->data[pos] = DoorComboSets[d].doorcombo_l[type][0];
5493 6362 scr->cset[pos] = DoorComboSets[d].doorcset_l[type][0];
5494 6362 scr->sflag[pos] = 0;
5495 6362 scr->data[pos+1] = DoorComboSets[d].doorcombo_l[type][1];
5496 6362 scr->cset[pos+1] = DoorComboSets[d].doorcset_l[type][1];
5497 6362 scr->sflag[pos+1] = 0;
5498 6362 scr->data[pos+16] = DoorComboSets[d].doorcombo_l[type][2];
5499 6362 scr->cset[pos+16] = DoorComboSets[d].doorcset_l[type][2];
5500 6362 scr->sflag[pos+16] = 0;
5501 6362 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_l[type][3];
5502 6362 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_l[type][3];
5503 6362 scr->sflag[pos+16+1] = 0;
5504 6362 scr->data[pos+32] = DoorComboSets[d].doorcombo_l[type][4];
5505 6362 scr->cset[pos+32] = DoorComboSets[d].doorcset_l[type][4];
5506 6362 scr->sflag[pos+32] = 0;
5507 6362 scr->data[pos+32+1] = DoorComboSets[d].doorcombo_l[type][5];
5508 6362 scr->cset[pos+32+1] = DoorComboSets[d].doorcset_l[type][5];
5509 6362 scr->sflag[pos+32+1] = 0;
5510
5511
2/2
✓ Branch 0 taken 4873 times.
✓ Branch 1 taken 1489 times.
6362 if(redraw)
5512 {
5513 2978 putcombo(dest,(pos&15)<<4,pos&0xF0,
5514 1489 DoorComboSets[d].doorcombo_l[type][0],
5515 1489 DoorComboSets[d].doorcset_l[type][0]);
5516 2978 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5517 1489 DoorComboSets[d].doorcombo_l[type][2],
5518 1489 DoorComboSets[d].doorcset_l[type][2]);
5519 2978 putcombo(dest,(pos&15)<<4,(pos&0xF0)+32,
5520 1489 DoorComboSets[d].doorcombo_l[type][4],
5521 1489 DoorComboSets[d].doorcset_l[type][4]);
5522 1489 }
5523
5524 6362 break;
5525
5526 case right:
5527 6712 scr->data[pos] = DoorComboSets[d].doorcombo_r[type][0];
5528 6712 scr->cset[pos] = DoorComboSets[d].doorcset_r[type][0];
5529 6712 scr->sflag[pos] = 0;
5530 6712 scr->data[pos+1] = DoorComboSets[d].doorcombo_r[type][1];
5531 6712 scr->cset[pos+1] = DoorComboSets[d].doorcset_r[type][1];
5532 6712 scr->sflag[pos+1] = 0;
5533 6712 scr->data[pos+16] = DoorComboSets[d].doorcombo_r[type][2];
5534 6712 scr->cset[pos+16] = DoorComboSets[d].doorcset_r[type][2];
5535 6712 scr->sflag[pos+16] = 0;
5536 6712 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_r[type][3];
5537 6712 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_r[type][3];
5538 6712 scr->sflag[pos+16+1] = 0;
5539 6712 scr->data[pos+32] = DoorComboSets[d].doorcombo_r[type][4];
5540 6712 scr->cset[pos+32] = DoorComboSets[d].doorcset_r[type][4];
5541 6712 scr->sflag[pos+32] = 0;
5542 6712 scr->data[pos+32+1] = DoorComboSets[d].doorcombo_r[type][5];
5543 6712 scr->cset[pos+32+1] = DoorComboSets[d].doorcset_r[type][5];
5544 6712 scr->sflag[pos+32+1] = 0;
5545
5546
2/2
✓ Branch 0 taken 5058 times.
✓ Branch 1 taken 1654 times.
6712 if(redraw)
5547 {
5548 3308 putcombo(dest,(pos&15)<<4,pos&0xF0,
5549 1654 DoorComboSets[d].doorcombo_r[type][0],
5550 1654 DoorComboSets[d].doorcset_r[type][0]);
5551 3308 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5552 1654 DoorComboSets[d].doorcombo_r[type][2],
5553 1654 DoorComboSets[d].doorcset_r[type][2]);
5554 3308 putcombo(dest,(pos&15)<<4,(pos&0xF0)+32,
5555 1654 DoorComboSets[d].doorcombo_r[type][4],
5556 1654 DoorComboSets[d].doorcset_r[type][4]);
5557 1654 }
5558
5559 6712 break;
5560 }
5561
5562 27117 break;
5563
5564 default:
5565 break;
5566 }
5567 28153 }
5568
5569 706556 static void over_door(mapscr* scr, BITMAP *dest, int32_t pos, int32_t side, int32_t offx, int32_t offy)
5570 {
5571 706556 int32_t door_combo_set = scr->door_combo_set;
5572 706556 int32_t x = (pos&15)<<4;
5573 706556 int32_t y = (pos&0xF0);
5574 706556 int32_t d = door_combo_set;
5575 706556 x += offx;
5576 706556 y += offy;
5577
5578
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 161136 times.
✓ Branch 2 taken 179643 times.
✓ Branch 3 taken 196353 times.
✓ Branch 4 taken 169424 times.
706556 switch(side)
5579 {
5580 case up:
5581 322272 overcombo2(dest,x,y,
5582 161136 DoorComboSets[d].bombdoorcombo_u[0],
5583 161136 DoorComboSets[d].bombdoorcset_u[0]);
5584 322272 overcombo2(dest,x+16,y,
5585 161136 DoorComboSets[d].bombdoorcombo_u[1],
5586 161136 DoorComboSets[d].bombdoorcset_u[1]);
5587 161136 break;
5588
5589 case down:
5590 359286 overcombo2(dest,x,y,
5591 179643 DoorComboSets[d].bombdoorcombo_d[0],
5592 179643 DoorComboSets[d].bombdoorcset_d[0]);
5593 359286 overcombo2(dest,x+16,y,
5594 179643 DoorComboSets[d].bombdoorcombo_d[1],
5595 179643 DoorComboSets[d].bombdoorcset_d[1]);
5596 179643 break;
5597
5598 case left:
5599 392706 overcombo2(dest,x,y,
5600 196353 DoorComboSets[d].bombdoorcombo_l[0],
5601 196353 DoorComboSets[d].bombdoorcset_l[0]);
5602 392706 overcombo2(dest,x,y+16,
5603 196353 DoorComboSets[d].bombdoorcombo_l[1],
5604 196353 DoorComboSets[d].bombdoorcset_l[1]);
5605 392706 overcombo2(dest,x,y+16,
5606 196353 DoorComboSets[d].bombdoorcombo_l[2],
5607 196353 DoorComboSets[d].bombdoorcset_l[2]);
5608 196353 break;
5609
5610 case right:
5611 338848 overcombo2(dest,x,y,
5612 169424 DoorComboSets[d].bombdoorcombo_r[0],
5613 169424 DoorComboSets[d].bombdoorcset_r[0]);
5614 338848 overcombo2(dest,x,y+16,
5615 169424 DoorComboSets[d].bombdoorcombo_r[1],
5616 169424 DoorComboSets[d].bombdoorcset_r[1]);
5617 338848 overcombo2(dest,x,y+16,
5618 169424 DoorComboSets[d].bombdoorcombo_r[2],
5619 169424 DoorComboSets[d].bombdoorcset_r[2]);
5620 169424 break;
5621 }
5622 706556 }
5623
5624 47568 void update_door(mapscr* scr, int32_t side, int32_t door, bool even_walls)
5625 {
5626
7/8
✓ Branch 0 taken 47460 times.
✓ Branch 1 taken 108 times.
✓ Branch 2 taken 47460 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22925 times.
✓ Branch 5 taken 24535 times.
✓ Branch 6 taken 530 times.
✓ Branch 7 taken 22395 times.
47568 if(door == dNONE || (!even_walls&&(door==dWALL||door==dWALK)))
5627 25173 return;
5628
5629 int32_t doortype;
5630
5631
10/12
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 655 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 12492 times.
✓ Branch 5 taken 910 times.
✓ Branch 6 taken 1553 times.
✓ Branch 7 taken 3192 times.
✓ Branch 8 taken 1694 times.
✓ Branch 9 taken 172 times.
✓ Branch 10 taken 67 times.
✓ Branch 11 taken 1138 times.
22395 switch(door)
5632 {
5633 case dWALL:
5634 doortype=dt_wall;
5635 break;
5636
5637 case dWALK:
5638 doortype=dt_walk;
5639 break;
5640
5641 case dOPEN:
5642 12492 doortype=dt_pass;
5643 12492 break;
5644
5645 case dLOCKED:
5646 910 doortype=dt_lock;
5647 910 break;
5648
5649 case dUNLOCKED:
5650 1553 doortype=dt_olck;
5651 1553 break;
5652
5653 case dSHUTTER:
5654
3/4
✓ Branch 0 taken 2783 times.
✓ Branch 1 taken 409 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2783 times.
3192 if(screenscrolling && ((HeroDir()^1)==side))
5655 {
5656 doortype=dt_osht;
5657 get_screen_state(scr->screen).open_doors = -4;
5658 break;
5659 }
5660
5661 [[fallthrough]];
5662 case d1WAYSHUTTER:
5663 3714 doortype=dt_shut;
5664 3714 break;
5665
5666 case dOPENSHUTTER:
5667 1694 doortype=dt_osht;
5668 1694 break;
5669
5670 case dBOSS:
5671 172 doortype=dt_boss;
5672 172 break;
5673
5674 case dOPENBOSS:
5675 67 doortype=dt_obos;
5676 67 break;
5677
5678 case dBOMBED:
5679 1138 doortype=dt_bomb;
5680 1138 break;
5681
5682 default:
5683 655 return;
5684 }
5685
5686
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 5629 times.
✓ Branch 2 taken 5770 times.
✓ Branch 3 taken 5111 times.
✓ Branch 4 taken 5230 times.
21740 switch(side)
5687 {
5688 case up:
5689 5629 put_door(scr,nullptr,7,side,doortype,false,even_walls);
5690 5629 break;
5691
5692 case down:
5693 5770 put_door(scr,nullptr,151,side,doortype,false,even_walls);
5694 5770 break;
5695
5696 case left:
5697 5111 put_door(scr,nullptr,64,side,doortype,false,even_walls);
5698 5111 break;
5699
5700 case right:
5701 5230 put_door(scr,nullptr,78,side,doortype,false,even_walls);
5702 5230 break;
5703 }
5704 47568 }
5705
5706 6504 void putdoor(mapscr* scr, BITMAP *dest, int32_t side, int32_t door, bool redraw, bool even_walls)
5707 {
5708 /*
5709 #define dWALL 0 // 000 0
5710 #define dBOMB 6 // 011 0
5711 #define 8 // 100 0
5712 enum {dt_pass=0, dt_lock, dt_shut, dt_boss, dt_olck, dt_osht, dt_obos, dt_wall, dt_bomb, dt_walk, dt_max};
5713 */
5714
5715
7/8
✓ Branch 0 taken 6504 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6500 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 6417 times.
✓ Branch 5 taken 83 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 6409 times.
6504 if(door == dNONE || (!even_walls&&(door==dWALL||door==dWALK)))
5716 91 return;
5717
5718 int32_t doortype;
5719
5720
8/12
✓ Branch 0 taken 227 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 362 times.
✓ Branch 7 taken 1530 times.
✓ Branch 8 taken 3958 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 51 times.
✓ Branch 11 taken 231 times.
6413 switch(door)
5721 {
5722 case dWALL:
5723 doortype=dt_wall;
5724 break;
5725
5726 case dWALK:
5727 doortype=dt_walk;
5728 break;
5729
5730 case dOPEN:
5731 50 doortype=dt_pass;
5732 50 break;
5733
5734 case dLOCKED:
5735 doortype=dt_lock;
5736 break;
5737
5738 case dUNLOCKED:
5739 362 doortype=dt_olck;
5740 362 break;
5741
5742 case dSHUTTER:
5743
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1530 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1530 if(screenscrolling && ((HeroDir()^1)==side))
5744 {
5745 doortype=dt_osht;
5746 get_screen_state(cur_screen).open_doors = -4;
5747 break;
5748 }
5749
5750 [[fallthrough]];
5751 case d1WAYSHUTTER:
5752 1757 doortype=dt_shut;
5753 1757 break;
5754
5755 case dOPENSHUTTER:
5756 3958 doortype=dt_osht;
5757 3958 break;
5758
5759 case dBOSS:
5760 4 doortype=dt_boss;
5761 4 break;
5762
5763 case dOPENBOSS:
5764 51 doortype=dt_obos;
5765 51 break;
5766
5767 case dBOMBED:
5768 231 doortype=dt_bomb;
5769 231 break;
5770
5771 default:
5772 return;
5773 }
5774
5775
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 1860 times.
✓ Branch 2 taken 1357 times.
✓ Branch 3 taken 1514 times.
✓ Branch 4 taken 1682 times.
6413 switch(side)
5776 {
5777 case up:
5778
2/2
✓ Branch 0 taken 1791 times.
✓ Branch 1 taken 69 times.
1860 switch(door)
5779 {
5780 case dBOMBED:
5781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
138 if(redraw)
5782 {
5783 69 over_door(scr,dest,39,side,0,0);
5784 69 }
5785 [[fallthrough]];
5786 default:
5787 1860 put_door(scr,dest,7,side,doortype,redraw, even_walls);
5788 1860 break;
5789 }
5790
5791 1860 break;
5792
5793 case down:
5794
2/2
✓ Branch 0 taken 1318 times.
✓ Branch 1 taken 39 times.
1357 switch(door)
5795 {
5796 case dBOMBED:
5797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
78 if(redraw)
5798 {
5799 39 over_door(scr,dest,135,side,0,0);
5800 39 }
5801 [[fallthrough]];
5802 default:
5803 1357 put_door(scr,dest,151,side,doortype,redraw, even_walls);
5804 1357 break;
5805 }
5806
5807 1357 break;
5808
5809 case left:
5810
2/2
✓ Branch 0 taken 1463 times.
✓ Branch 1 taken 51 times.
1514 switch(door)
5811 {
5812 case dBOMBED:
5813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
102 if(redraw)
5814 {
5815 51 over_door(scr,dest,66,side,0,0);
5816 51 }
5817 [[fallthrough]];
5818 default:
5819 1514 put_door(scr,dest,64,side,doortype,redraw, even_walls);
5820 1514 break;
5821 }
5822
5823 1514 break;
5824
5825 case right:
5826
2/2
✓ Branch 0 taken 1610 times.
✓ Branch 1 taken 72 times.
1682 switch(door)
5827 {
5828 case dBOMBED:
5829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
144 if(redraw)
5830 {
5831 72 over_door(scr,dest,77,side,0,0);
5832 72 }
5833 [[fallthrough]];
5834 default:
5835 1682 put_door(scr,dest,78,side,doortype,redraw, even_walls);
5836 1682 break;
5837 }
5838
5839 1682 break;
5840 }
5841 6504 }
5842
5843 586 void putcombo_not_zero(BITMAP *dest, int32_t x, int32_t y, int32_t combo, int32_t cset)
5844 {
5845
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if(combo!=0)
5846 {
5847 586 putcombo(dest,x, y, combo, cset);
5848 586 }
5849 586 }
5850
5851 293 void overcombo_not_zero(BITMAP *dest, int32_t x, int32_t y, int32_t combo, int32_t cset)
5852 {
5853
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 74 times.
293 if(combo!=0)
5854 {
5855 219 overcombo(dest,x, y, combo, cset);
5856 219 }
5857 293 }
5858
5859 125 void showbombeddoor(mapscr* scr, BITMAP *dest, int32_t side, int32_t offx, int32_t offy)
5860 {
5861 125 int32_t d = scr->door_combo_set;
5862
5863
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 37 times.
125 switch(side)
5864 {
5865 case up:
5866 86 putcombo_not_zero(dest,((7&15)<<4) + offx,(7&0xF0) + offy,
5867 43 DoorComboSets[d].doorcombo_u[dt_bomb][0],
5868 43 DoorComboSets[d].doorcset_u[dt_bomb][0]);
5869 86 putcombo_not_zero(dest,((8&15)<<4) + offx,(8&0xF0) + offy,
5870 43 DoorComboSets[d].doorcombo_u[dt_bomb][1],
5871 43 DoorComboSets[d].doorcset_u[dt_bomb][1]);
5872 86 putcombo_not_zero(dest,((23&15)<<4) + offx,(23&0xF0) + offy,
5873 43 DoorComboSets[d].doorcombo_u[dt_bomb][2],
5874 43 DoorComboSets[d].doorcset_u[dt_bomb][2]);
5875 86 putcombo_not_zero(dest,((24&15)<<4) + offx,(24&0xF0) + offy,
5876 43 DoorComboSets[d].doorcombo_u[dt_bomb][3],
5877 43 DoorComboSets[d].doorcset_u[dt_bomb][3]);
5878 86 overcombo_not_zero(dest,((39&15)<<4) + offx,(39&0xF0) + offy,
5879 43 DoorComboSets[d].bombdoorcombo_u[0],
5880 43 DoorComboSets[d].bombdoorcset_u[0]);
5881 86 overcombo_not_zero(dest,((40&15)<<4) + offx,(40&0xF0) + offy,
5882 43 DoorComboSets[d].bombdoorcombo_u[1],
5883 43 DoorComboSets[d].bombdoorcset_u[1]);
5884 43 break;
5885
5886 case down:
5887 78 putcombo_not_zero(dest,((151&15)<<4) + offx,(151&0xF0) + offy,
5888 39 DoorComboSets[d].doorcombo_d[dt_bomb][0],
5889 39 DoorComboSets[d].doorcset_d[dt_bomb][0]);
5890 78 putcombo_not_zero(dest,((152&15)<<4) + offx,(152&0xF0) + offy,
5891 39 DoorComboSets[d].doorcombo_d[dt_bomb][1],
5892 39 DoorComboSets[d].doorcset_d[dt_bomb][1]);
5893 78 putcombo_not_zero(dest,((167&15)<<4) + offx,(167&0xF0) + offy,
5894 39 DoorComboSets[d].doorcombo_d[dt_bomb][2],
5895 39 DoorComboSets[d].doorcset_d[dt_bomb][2]);
5896 78 putcombo_not_zero(dest,((168&15)<<4) + offx,(168&0xF0) + offy,
5897 39 DoorComboSets[d].doorcombo_d[dt_bomb][3],
5898 39 DoorComboSets[d].doorcset_d[dt_bomb][3]);
5899 78 overcombo_not_zero(dest,((135&15)<<4) + offx,(135&0xF0) + offy,
5900 39 DoorComboSets[d].bombdoorcombo_d[0],
5901 39 DoorComboSets[d].bombdoorcset_d[0]);
5902 78 overcombo_not_zero(dest,((136&15)<<4) + offx,(136&0xF0) + offy,
5903 39 DoorComboSets[d].bombdoorcombo_d[1],
5904 39 DoorComboSets[d].bombdoorcset_d[1]);
5905 39 break;
5906
5907 case left:
5908 12 putcombo_not_zero(dest,((64&15)<<4) + offx,(64&0xF0) + offy,
5909 6 DoorComboSets[d].doorcombo_l[dt_bomb][0],
5910 6 DoorComboSets[d].doorcset_l[dt_bomb][0]);
5911 12 putcombo_not_zero(dest,((65&15)<<4) + offx,(65&0xF0) + offy,
5912 6 DoorComboSets[d].doorcombo_l[dt_bomb][1],
5913 6 DoorComboSets[d].doorcset_l[dt_bomb][1]);
5914 12 putcombo_not_zero(dest,((80&15)<<4) + offx,(80&0xF0) + offy,
5915 6 DoorComboSets[d].doorcombo_l[dt_bomb][2],
5916 6 DoorComboSets[d].doorcset_l[dt_bomb][2]);
5917 12 putcombo_not_zero(dest,((81&15)<<4) + offx,(81&0xF0) + offy,
5918 6 DoorComboSets[d].doorcombo_l[dt_bomb][3],
5919 6 DoorComboSets[d].doorcset_l[dt_bomb][3]);
5920 12 putcombo_not_zero(dest,((96&15)<<4) + offx,(96&0xF0) + offy,
5921 6 DoorComboSets[d].doorcombo_l[dt_bomb][4],
5922 6 DoorComboSets[d].doorcset_l[dt_bomb][4]);
5923 12 putcombo_not_zero(dest,((97&15)<<4) + offx,(97&0xF0) + offy,
5924 6 DoorComboSets[d].doorcombo_l[dt_bomb][5],
5925 6 DoorComboSets[d].doorcset_l[dt_bomb][5]);
5926 12 overcombo_not_zero(dest,((66&15)<<4) + offx,(66&0xF0) + offy,
5927 6 DoorComboSets[d].bombdoorcombo_l[0],
5928 6 DoorComboSets[d].bombdoorcset_l[0]);
5929 12 overcombo_not_zero(dest,((82&15)<<4) + offx,(82&0xF0) + offy,
5930 6 DoorComboSets[d].bombdoorcombo_l[1],
5931 6 DoorComboSets[d].bombdoorcset_l[1]);
5932 12 overcombo_not_zero(dest,((98&15)<<4) + offx,(98&0xF0) + offy,
5933 6 DoorComboSets[d].bombdoorcombo_l[2],
5934 6 DoorComboSets[d].bombdoorcset_l[2]);
5935 6 break;
5936
5937 case right:
5938 74 putcombo_not_zero(dest,((78&15)<<4) + offx,(78&0xF0) + offy,
5939 37 DoorComboSets[d].doorcombo_r[dt_bomb][0],
5940 37 DoorComboSets[d].doorcset_r[dt_bomb][0]);
5941 74 putcombo_not_zero(dest,((79&15)<<4) + offx,(79&0xF0) + offy,
5942 37 DoorComboSets[d].doorcombo_r[dt_bomb][1],
5943 37 DoorComboSets[d].doorcset_r[dt_bomb][1]);
5944 74 putcombo_not_zero(dest,((94&15)<<4) + offx,(94&0xF0) + offy,
5945 37 DoorComboSets[d].doorcombo_r[dt_bomb][2],
5946 37 DoorComboSets[d].doorcset_r[dt_bomb][2]);
5947 74 putcombo_not_zero(dest,((95&15)<<4) + offx,(95&0xF0) + offy,
5948 37 DoorComboSets[d].doorcombo_r[dt_bomb][3],
5949 37 DoorComboSets[d].doorcset_r[dt_bomb][3]);
5950 74 putcombo_not_zero(dest,((110&15)<<4) + offx,(110&0xF0) + offy,
5951 37 DoorComboSets[d].doorcombo_r[dt_bomb][4],
5952 37 DoorComboSets[d].doorcset_r[dt_bomb][4]);
5953 74 putcombo_not_zero(dest,((111&15)<<4) + offx,(111&0xF0) + offy,
5954 37 DoorComboSets[d].doorcombo_r[dt_bomb][5],
5955 37 DoorComboSets[d].doorcset_r[dt_bomb][5]);
5956 74 overcombo_not_zero(dest,((77&15)<<4) + offx,(77&0xF0) + offy,
5957 37 DoorComboSets[d].bombdoorcombo_r[0],
5958 37 DoorComboSets[d].bombdoorcset_r[0]);
5959 74 overcombo_not_zero(dest,((93&15)<<4) + offx,(93&0xF0) + offy,
5960 37 DoorComboSets[d].bombdoorcombo_r[1],
5961 37 DoorComboSets[d].bombdoorcset_r[1]);
5962 74 overcombo_not_zero(dest,((109&15)<<4) + offx,(109&0xF0) + offy,
5963 37 DoorComboSets[d].bombdoorcombo_r[2],
5964 37 DoorComboSets[d].bombdoorcset_r[2]);
5965 37 break;
5966 }
5967 125 }
5968
5969 5362717 void openshutters(mapscr* scr)
5970 {
5971 5362717 bool opened_door = false;
5972
2/2
✓ Branch 0 taken 5362717 times.
✓ Branch 1 taken 21450868 times.
26813585 for(int32_t i=0; i<4; i++)
5973
2/2
✓ Branch 0 taken 21446910 times.
✓ Branch 1 taken 3958 times.
21454826 if(scr->door[i]==dSHUTTER)
5974 {
5975 3958 putdoor(scr, scrollbuf, i, dOPENSHUTTER);
5976 3958 scr->door[i]=dOPENSHUTTER;
5977 3958 opened_door = true;
5978 3958 }
5979
5980 5362717 auto& combo_cache = combo_caches::shutter;
5981 2075592905 for_every_combo_in_screen(create_screen_handles(scr), [&](const auto& handle) {
5982
3/4
✓ Branch 0 taken 2068619513 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1610668 times.
✗ Branch 3 not taken.
2070230188 if (!combo_cache.minis[handle.data()].shutter)
5983 2070230181 return;
5984
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 trig_each_combo_trigger(handle, [&](combo_trigger const& trig){
5985 7 return trig.trigger_flags.get(TRIGFLAG_SHUTTER);
5986 });
5987 2070230188 });
5988
5989
2/2
✓ Branch 0 taken 5359986 times.
✓ Branch 1 taken 2731 times.
5362717 if(opened_door)
5990 2731 sfx(WAV_DOOR);
5991 5362717 }
5992
5993 15122136 void clear_darkroom_bitmaps()
5994 {
5995 15122136 clear_to_color(darkscr_bmp, game->get_darkscr_color());
5996 15122136 clear_to_color(darkscr_bmp_trans, game->get_darkscr_color());
5997 15122136 }
5998
5999 16036597 bool is_dark(const mapscr* scr)
6000 {
6001 16036597 bool dark = scr->flags&fDARK;
6002
2/2
✓ Branch 0 taken 3722 times.
✓ Branch 1 taken 16032875 times.
16036597 if (region_is_lit) return !dark;
6003 16032875 return dark;
6004 16036597 }
6005
6006 39226 bool scrolling_is_dark(const mapscr* scr)
6007 {
6008 39226 bool dark = scr->flags&fDARK;
6009
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 39224 times.
39226 if (scrolling_region_is_lit) return !dark;
6010 39224 return dark;
6011 39226 }
6012
6013 36761 bool is_any_dark()
6014 {
6015 36761 bool dark = false;
6016 74778 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
6017 38017 dark |= (bool)(is_dark(scr));
6018 38017 });
6019 36761 return dark;
6020 }
6021
6022
3/4
✓ Branch 0 taken 2919 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2502 times.
✓ Branch 3 taken 417 times.
2919 static mapscr prev_origin_scrs[7];
6023 417 static std::set<int> loadscr_ffc_script_ids_to_remove;
6024
6025 static void handle_screen_overlay(const std::vector<mapscr*>& screens)
6026 {
6027 mapscr* base_scr = screens[0];
6028 mapscr* previous_scr = &prev_origin_scrs[0];
6029
6030 for (int i = 0; i < 176; i++)
6031 {
6032 if (base_scr->data[i] == 0)
6033 {
6034 base_scr->data[i] = previous_scr->data[i];
6035 base_scr->sflag[i] = previous_scr->sflag[i];
6036 base_scr->cset[i] = previous_scr->cset[i];
6037 }
6038 }
6039
6040 for (int i = 0; i < 6; i++)
6041 {
6042 if (previous_scr->layermap[i] > 0 && base_scr->layermap[i] > 0)
6043 {
6044 int lm = (base_scr->layermap[i]-1)*MAPSCRS+base_scr->layerscreen[i];
6045 int fm = (previous_scr->layermap[i]-1)*MAPSCRS+previous_scr->layerscreen[i];
6046
6047 for (int j = 0; j < 176; j++)
6048 {
6049 if (TheMaps[lm].data[j] == 0)
6050 {
6051 TheMaps[lm].data[j] = TheMaps[fm].data[j];
6052 TheMaps[lm].sflag[j] = TheMaps[fm].sflag[j];
6053 TheMaps[lm].cset[j] = TheMaps[fm].cset[j];
6054 }
6055 }
6056 }
6057 }
6058
6059 for (int i = 1; i <= 6; i++)
6060 {
6061 mapscr* scr = screens[i];
6062 previous_scr = &prev_origin_scrs[i];
6063
6064 if (scr->layermap[i] > 0)
6065 {
6066 for (int y = 0; y < 11; y++)
6067 {
6068 for (int x = 0; x < 16; x++)
6069 {
6070 int c = y*16+x;
6071
6072 if (scr->data[c]==0)
6073 {
6074 scr->data[c] = previous_scr->data[c];
6075 scr->sflag[c] = previous_scr->sflag[c];
6076 scr->cset[c] = previous_scr->cset[c];
6077 }
6078 }
6079 }
6080 }
6081 }
6082 }
6083
6084 37101 static void load_a_screen_and_layers_init(int dmap, int screen, int ldir, bool screen_overlay, bool ffc_overlay)
6085 {
6086 37101 std::vector<mapscr*> screens;
6087
6088
1/2
✓ Branch 0 taken 37101 times.
✗ Branch 1 not taken.
37101 const mapscr* source = get_canonical_scr(cur_map, screen);
6089
2/4
✓ Branch 0 taken 37101 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37101 times.
✗ Branch 3 not taken.
37101 mapscr* base_scr = new mapscr(*source);
6090 37101 temporary_screens[screen*7] = base_scr;
6091
1/2
✓ Branch 0 taken 37101 times.
✗ Branch 1 not taken.
37101 screens.push_back(base_scr);
6092
6093 37101 base_scr->valid |= mVALID; // layer 0 is always valid
6094
6095
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 35857 times.
37101 if (screen == cur_screen)
6096 35857 origin_scr = base_scr;
6097
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 35857 times.
37101 if (screen == Hero.current_screen)
6098 35857 hero_scr = prev_hero_scr = base_scr;
6099
6100
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 36982 times.
37101 if (source->script > 0)
6101
1/2
✓ Branch 0 taken 119 times.
✗ Branch 1 not taken.
119 FFCore.reset_script_engine_data(ScriptType::Screen, screen);
6102
6103
2/2
✓ Branch 0 taken 37101 times.
✓ Branch 1 taken 222606 times.
259707 for (int i = 0; i < 6; i++)
6104 {
6105
2/2
✓ Branch 0 taken 173517 times.
✓ Branch 1 taken 49089 times.
222606 if(source->layermap[i]>0)
6106 {
6107
3/6
✓ Branch 0 taken 49089 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49089 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 49089 times.
✗ Branch 5 not taken.
49089 mapscr* layer_scr = new mapscr(*get_canonical_scr(source->layermap[i]-1, source->layerscreen[i]));
6108 49089 layer_scr->map = cur_map;
6109 49089 layer_scr->screen = screen;
6110 49089 layer_scr->valid |= mVALID;
6111
1/2
✓ Branch 0 taken 49089 times.
✗ Branch 1 not taken.
49089 screens.push_back(layer_scr);
6112 49089 }
6113 else
6114 {
6115
2/4
✓ Branch 0 taken 173517 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 173517 times.
✗ Branch 3 not taken.
173517 mapscr* layer_scr = new mapscr();
6116 173517 layer_scr->map = cur_map;
6117 173517 layer_scr->screen = screen;
6118
1/2
✓ Branch 0 taken 173517 times.
✗ Branch 1 not taken.
173517 screens.push_back(layer_scr);
6119 }
6120 222606 temporary_screens[screen*7+i+1] = screens[i+1];
6121 222606 }
6122
6123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37101 times.
37101 if (screen_overlay)
6124 handle_screen_overlay(screens);
6125
6126
2/2
✓ Branch 0 taken 145 times.
✓ Branch 1 taken 36956 times.
37101 if (ffc_overlay)
6127 {
6128 145 mapscr* previous_scr = &prev_origin_scrs[0];
6129
1/2
✓ Branch 0 taken 145 times.
✗ Branch 1 not taken.
145 int num_ffcs = previous_scr->numFFC();
6130
2/2
✓ Branch 0 taken 4640 times.
✓ Branch 1 taken 145 times.
4785 for (int i = 0; i < num_ffcs; i++)
6131 {
6132
2/2
✓ Branch 0 taken 4365 times.
✓ Branch 1 taken 275 times.
4640 if ((previous_scr->ffcs[i].flags&ffc_carryover))
6133 {
6134
2/4
✓ Branch 0 taken 275 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 275 times.
✗ Branch 3 not taken.
275 auto& ffc = base_scr->getFFC(i) = previous_scr->ffcs[i];
6135 275 ffc.screen_spawned = screen;
6136
6137
1/2
✓ Branch 0 taken 275 times.
✗ Branch 1 not taken.
275 ffc_id_t ffc_id = get_region_screen_offset(screen)*MAXFFCS + i;
6138
1/2
✓ Branch 0 taken 275 times.
✗ Branch 1 not taken.
275 loadscr_ffc_script_ids_to_remove.erase(ffc_id);
6139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 275 times.
275 if (previous_scr->ffcs[i].flags&ffc_scriptreset)
6140 {
6141 FFCore.reset_script_engine_data(ScriptType::FFC, ffc_id);
6142 }
6143 275 }
6144 4640 }
6145 145 }
6146
6147
1/2
✓ Branch 0 taken 37101 times.
✗ Branch 1 not taken.
1141981 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
6148
1/2
✓ Branch 0 taken 37101 times.
✗ Branch 1 not taken.
37101 int num_ffcs = base_scr->numFFC();
6149
2/2
✓ Branch 0 taken 1104880 times.
✓ Branch 1 taken 37101 times.
1141981 for (word i = 0; i < num_ffcs; i++)
6150 {
6151 1104880 base_scr->ffcs[i].screen_spawned = screen;
6152
1/2
✓ Branch 0 taken 1104880 times.
✗ Branch 1 not taken.
1104880 base_scr->ffcs[i].x += offx;
6153
1/2
✓ Branch 0 taken 1104880 times.
✗ Branch 1 not taken.
1104880 base_scr->ffcs[i].y += offy;
6154 1104880 }
6155 37101 }
6156
6157 37101 static void load_a_screen_and_layers_post(int dmap, int screen, int ldir)
6158 {
6159 37101 mapscr* base_scr = get_scr(screen);
6160 37101 int mi = mapind(cur_map, screen);
6161
6162 // Apply perm secrets, if applicable.
6163
2/2
✓ Branch 0 taken 11520 times.
✓ Branch 1 taken 25581 times.
37101 if (canPermSecret(dmap, screen))
6164 {
6165
2/2
✓ Branch 0 taken 23056 times.
✓ Branch 1 taken 2525 times.
25581 if(game->maps[mi] & mSECRET) // if special stuff done before
6166 {
6167 2525 reveal_hidden_stairs(base_scr, screen, false);
6168 2525 trigger_secrets_for_screen(TriggerSource::SecretsScreenState, base_scr, false);
6169 2525 }
6170
2/2
✓ Branch 0 taken 25578 times.
✓ Branch 1 taken 3 times.
25581 if(game->maps[mi] & mLIGHTBEAM) // if special stuff done before
6171 {
6172
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 3 times.
24 for (int layer = 0; layer <= 6; layer++)
6173 {
6174 21 mapscr* layer_scr = get_scr_layer(screen, layer);
6175
2/2
✓ Branch 0 taken 3696 times.
✓ Branch 1 taken 21 times.
3717 for (int pos = 0; pos < 176; pos++)
6176 {
6177 3696 newcombo const* cmb = &combobuf[layer_scr->data[pos]];
6178
2/2
✓ Branch 0 taken 3693 times.
✓ Branch 1 taken 3 times.
3696 if(cmb->type == cLIGHTTARGET)
6179 {
6180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!(cmb->usrflags&cflag1)) //Unlit version
6181 {
6182 3 layer_scr->data[pos] += 1;
6183 3 }
6184 3 }
6185 3696 }
6186 21 }
6187 3 }
6188 25581 }
6189
6190 37101 auto screen_handles = create_screen_handles(base_scr);
6191
6192 37101 int destlvl = DMaps[dmap].level;
6193 37101 toggle_switches(game->lvlswitches[destlvl], true, screen_handles);
6194 37101 toggle_gswitches_load(screen_handles);
6195
6196 37101 bool should_check_for_state_things = (screen < 0x80);
6197
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 36194 times.
37101 if (should_check_for_state_things)
6198 {
6199
2/2
✓ Branch 0 taken 35822 times.
✓ Branch 1 taken 372 times.
36194 if (game->maps[mi]&mLOCKBLOCK)
6200 372 remove_lockblocks(screen_handles);
6201
2/2
✓ Branch 0 taken 36136 times.
✓ Branch 1 taken 58 times.
36194 if (game->maps[mi]&mBOSSLOCKBLOCK)
6202 58 remove_bosslockblocks(screen_handles);
6203
2/2
✓ Branch 0 taken 36038 times.
✓ Branch 1 taken 156 times.
36194 if (game->maps[mi]&mCHEST)
6204 156 remove_chests(screen_handles);
6205
1/2
✓ Branch 0 taken 36194 times.
✗ Branch 1 not taken.
36194 if (game->maps[mi]&mLOCKEDCHEST)
6206 remove_lockedchests(screen_handles);
6207
2/2
✓ Branch 0 taken 36183 times.
✓ Branch 1 taken 11 times.
36194 if (game->maps[mi]&mBOSSCHEST)
6208 11 remove_bosschests(screen_handles);
6209
6210 36194 clear_xdoors_mi(screen_handles, mi, true);
6211 36194 clear_xstatecombos_mi(screen_handles, mi, true);
6212 36194 }
6213
6214 // check doors
6215
2/2
✓ Branch 0 taken 25580 times.
✓ Branch 1 taken 11521 times.
37101 if (isdungeon(dmap, screen))
6216 {
6217
2/2
✓ Branch 0 taken 46084 times.
✓ Branch 1 taken 11521 times.
57605 for(int32_t i=0; i<4; i++)
6218 {
6219 46084 int32_t door=base_scr->door[i];
6220
6221
5/5
✓ Branch 0 taken 5303 times.
✓ Branch 1 taken 36475 times.
✓ Branch 2 taken 2372 times.
✓ Branch 3 taken 230 times.
✓ Branch 4 taken 1704 times.
46084 switch(door)
6222 {
6223 case d1WAYSHUTTER:
6224 case dSHUTTER:
6225
3/4
✓ Branch 0 taken 1694 times.
✓ Branch 1 taken 3609 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1694 times.
5303 if ((ldir^1)==i && screen == Hero.current_screen)
6226 {
6227 1694 base_scr->door[i]=dOPENSHUTTER;
6228 1694 }
6229
6230 5303 get_screen_state(screen).open_doors = -4;
6231 5303 break;
6232
6233 case dLOCKED:
6234
3/4
✓ Branch 0 taken 2372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1473 times.
✓ Branch 3 taken 899 times.
2372 if(should_check_for_state_things && game->maps[mi]&(mDOOR_UP<<i))
6235 {
6236 1473 base_scr->door[i]=dUNLOCKED;
6237 1473 }
6238
6239 2372 break;
6240
6241 case dBOSS:
6242
3/4
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 168 times.
230 if(should_check_for_state_things && game->maps[mi]&(mDOOR_UP<<i))
6243 {
6244 62 base_scr->door[i]=dOPENBOSS;
6245 62 }
6246
6247 230 break;
6248
6249 case dBOMB:
6250
3/4
✓ Branch 0 taken 1704 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1087 times.
✓ Branch 3 taken 617 times.
1704 if(should_check_for_state_things && game->maps[mi]&(mDOOR_UP<<i))
6251 {
6252 1087 base_scr->door[i]=dBOMBED;
6253 1087 }
6254
6255 1704 break;
6256 }
6257
6258 46084 update_door(base_scr, i, base_scr->door[i]);
6259
6260
4/4
✓ Branch 0 taken 41517 times.
✓ Branch 1 taken 4567 times.
✓ Branch 2 taken 736 times.
✓ Branch 3 taken 40781 times.
46084 if(door==dSHUTTER||door==d1WAYSHUTTER)
6261 {
6262 5303 base_scr->door[i]=door;
6263 5303 }
6264 46084 }
6265 11521 }
6266
6267
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 36964 times.
37101 if (!(base_scr->flags3 & fCYCLEONINIT))
6268 36964 return;
6269
6270
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 959 times.
1096 for (int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6271 {
6272
4/4
✓ Branch 0 taken 822 times.
✓ Branch 1 taken 137 times.
✓ Branch 2 taken 377 times.
✓ Branch 3 taken 445 times.
959 if (j<0 || base_scr->layermap[j] > 0)
6273 {
6274 514 mapscr* layer_scr = get_scr_layer(screen, j + 1);
6275
3/4
✓ Branch 0 taken 377 times.
✓ Branch 1 taken 137 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 377 times.
514 mapscr* layerscreen= (j<0 ? base_scr : layer_scr->valid ? layer_scr :
6276 &TheMaps[(base_scr->layermap[j]-1)*MAPSCRS]+base_scr->layerscreen[j]);
6277
6278
2/2
✓ Branch 0 taken 90464 times.
✓ Branch 1 taken 514 times.
90978 for(int32_t i=0; i<176; ++i)
6279 {
6280 90464 int32_t c=layerscreen->data[i];
6281
6282 // New screen flag: Cycle Combos At Screen Init
6283
5/6
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 90399 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
90464 if(combobuf[c].nextcombo != 0 && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6284 {
6285 65 int32_t r = 0;
6286
6287
4/4
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 65 times.
149 while(combobuf[c].can_cycle() && r++ < 10)
6288 {
6289 84 newcombo const& cmb = combobuf[c];
6290 84 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6292 84 layerscreen->data[i] = cid;
6293
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 69 times.
84 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
69 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6295 84 c = layerscreen->data[i];
6296 }
6297 65 }
6298 90464 }
6299 514 }
6300 959 }
6301 37101 }
6302
6303 // Set `cur_screen` to `screen` and load new screens into temporary memory.
6304 //
6305 // Called anytime a player moves to a new screen (either via warping, scrolling, continue, starting
6306 // the game, etc...)
6307 //
6308 // Note: for regions, only the initial screen load calls this function. Simply walking between
6309 // screens in the same region does not use this, because every screen in a region is loaded into
6310 // temporary memory up front.
6311 //
6312 // If scr >= 0x80, `Hero.current_screen` will be saved to `home_screen` and also be loaded into
6313 // `special_warp_return_scr`.
6314 //
6315 // If origin_screen_overlay is true, the old origin_scr combos will be copied to the new origin_scr combos
6316 // on all layers (but only where the new screen has a 0 combo).
6317 //
6318 // TODO: loadscr should set curdmap, but currently callers do that.
6319 35857 void loadscr(int32_t destdmap, int32_t screen, int32_t ldir, bool origin_screen_overlay, bool no_x80_dir)
6320 {
6321 35857 zapp_reporting_set_tag("screen", screen);
6322
2/2
✓ Branch 0 taken 8931 times.
✓ Branch 1 taken 26926 times.
35857 if (destdmap != -1)
6323 8931 zapp_reporting_set_tag("dmap", destdmap);
6324
6325 35857 int32_t orig_destdmap = destdmap;
6326
2/2
✓ Branch 0 taken 8931 times.
✓ Branch 1 taken 26926 times.
35857 if (destdmap < 0) destdmap = cur_dmap;
6327
6328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35857 times.
35857 if (replay_is_active())
6329 {
6330
2/2
✓ Branch 0 taken 26926 times.
✓ Branch 1 taken 8931 times.
35857 if (orig_destdmap != -1)
6331 {
6332
2/2
✓ Branch 0 taken 7860 times.
✓ Branch 1 taken 1071 times.
8931 if (strlen(DMaps[orig_destdmap].name) > 0)
6333 {
6334
1/2
✓ Branch 0 taken 7860 times.
✗ Branch 1 not taken.
7860 replay_step_comment(fmt::format("dmap={} {}", orig_destdmap, DMaps[orig_destdmap].name));
6335 7860 }
6336 else
6337 {
6338
1/2
✓ Branch 0 taken 1071 times.
✗ Branch 1 not taken.
1071 replay_step_comment(fmt::format("dmap={}", orig_destdmap));
6339 }
6340 8931 }
6341 35857 replay_step_comment_loadscr(screen);
6342
6343 // Reset the rngs and frame count so that recording steps can be modified without impacting
6344 // behavior of later screens.
6345 35857 replay_sync_rng();
6346 35857 }
6347
6348
2/2
✓ Branch 0 taken 1707537 times.
✓ Branch 1 taken 35857 times.
1743394 for (auto& state : get_screen_states())
6349 1707537 state.second.triggered_secrets = false;
6350 35857 slopes.clear();
6351 35857 Hero.clear_platform_ffc();
6352 35857 timeExitAllGenscript(GENSCR_ST_CHANGE_SCREEN);
6353 35857 clear_darkroom_bitmaps();
6354 35857 msgscr = nullptr;
6355
6356
2/2
✓ Branch 0 taken 50400467 times.
✓ Branch 1 taken 35857 times.
50436324 for (word x=0; x<animated_combos; x++)
6357 {
6358
2/2
✓ Branch 0 taken 20920135 times.
✓ Branch 1 taken 29480332 times.
50400467 if(combobuf[animated_combo_table4[x][0]].nextcombo!=0)
6359 {
6360 20920135 combobuf[animated_combo_table4[x][0]].aclk = 0;
6361 20920135 }
6362 50400467 }
6363 35857 reset_combo_animations2();
6364 35857 region_is_lit = false;
6365
6366 // Legacy features (combo and ffc overlays) may need the previous origin screens during loading
6367 // of the new ones.
6368 35857 bool origin_ffc_overlay = false;
6369
2/2
✓ Branch 0 taken 1139 times.
✓ Branch 1 taken 34718 times.
35857 if (origin_scr)
6370 {
6371
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 34716 times.
34718 if (!(origin_scr->flags5&fNOFFCARRYOVER))
6372 {
6373 34716 int c = origin_scr->numFFC();
6374
2/2
✓ Branch 0 taken 34571 times.
✓ Branch 1 taken 1038911 times.
1073482 for (int i = 0; i < c; i++)
6375 {
6376
2/2
✓ Branch 0 taken 1038766 times.
✓ Branch 1 taken 145 times.
1038911 if (origin_scr->ffcs[i].flags&ffc_carryover)
6377 {
6378 145 origin_ffc_overlay = true;
6379 145 break;
6380 }
6381 1038766 }
6382 34716 }
6383
6384
3/4
✓ Branch 0 taken 34718 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 145 times.
✓ Branch 3 taken 34573 times.
34718 if (origin_screen_overlay || origin_ffc_overlay)
6385 {
6386
2/2
✓ Branch 0 taken 1015 times.
✓ Branch 1 taken 145 times.
1160 for (int i = 0; i <= 6; i++)
6387 {
6388 1015 mapscr* prev_scr = get_scr_layer(cur_screen, i);
6389
1/2
✓ Branch 0 taken 1015 times.
✗ Branch 1 not taken.
1015 if (prev_scr)
6390 1015 prev_origin_scrs[i] = *prev_scr;
6391 else
6392 prev_origin_scrs[i] = {};
6393 1015 }
6394 145 }
6395 34718 }
6396
6397 // When loading a new screen, all previous FFC scripts end, with one exception.
6398 // Based on origin_ffc_overlay, some ffc scripts don't get reset. This set starts with all of
6399 // them, but scripts that need their data to persist will be removed.
6400 35857 loadscr_ffc_script_ids_to_remove.clear();
6401
2/2
✓ Branch 0 taken 74701318 times.
✓ Branch 1 taken 35857 times.
74737175 for (auto& key : scriptEngineDatas | std::views::keys)
6402 {
6403
2/2
✓ Branch 0 taken 73579381 times.
✓ Branch 1 taken 1121937 times.
74701318 if (key.first == ScriptType::FFC)
6404 1121937 loadscr_ffc_script_ids_to_remove.insert(key.second);
6405 }
6406
6407 35857 load_region(destdmap, screen);
6408
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 34950 times.
35857 home_screen = screen >= 0x80 ? Hero.current_screen : cur_screen;
6409 35857 Hero.current_screen = screen;
6410
6411 35857 cpos_clear_all();
6412 35857 FFCore.destroyScriptableObjectsOfType(ScriptType::Screen);
6413 35857 FFCore.clear_combo_scripts();
6414
6415
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 35693 times.
35857 if (is_in_scrolling_region())
6416 {
6417
2/2
✓ Branch 0 taken 20992 times.
✓ Branch 1 taken 164 times.
21156 for (int screen = 0; screen < 128; screen++)
6418 {
6419
2/2
✓ Branch 0 taken 19584 times.
✓ Branch 1 taken 1408 times.
20992 if (is_in_current_region(screen))
6420 {
6421
1/2
✓ Branch 0 taken 1408 times.
✗ Branch 1 not taken.
1408 bool screen_overlay = origin_screen_overlay && screen == cur_screen;
6422
1/2
✓ Branch 0 taken 1408 times.
✗ Branch 1 not taken.
1408 bool ffc_overlay = origin_ffc_overlay && screen == cur_screen;
6423 1408 load_a_screen_and_layers_init(destdmap, screen, ldir, screen_overlay, ffc_overlay);
6424 1408 }
6425 20992 }
6426 164 }
6427 else
6428 {
6429 35693 load_a_screen_and_layers_init(destdmap, screen, ldir, origin_screen_overlay, origin_ffc_overlay);
6430 }
6431
6432 35857 prepare_current_region_handles();
6433
6434
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 35693 times.
35857 if (is_in_scrolling_region())
6435 {
6436
2/2
✓ Branch 0 taken 20992 times.
✓ Branch 1 taken 164 times.
21156 for (int screen = 0; screen < 128; screen++)
6437 {
6438
2/2
✓ Branch 0 taken 19584 times.
✓ Branch 1 taken 1408 times.
20992 if (is_in_current_region(screen))
6439 {
6440 1408 load_a_screen_and_layers_post(destdmap, screen, ldir);
6441 1408 }
6442 20992 }
6443 164 }
6444 else
6445 {
6446 35693 load_a_screen_and_layers_post(destdmap, screen, ldir);
6447 }
6448
6449 // If on a special screen, load the screen the player is currently on (home_screen) into special_warp_return_scr.
6450
2/2
✓ Branch 0 taken 34950 times.
✓ Branch 1 taken 907 times.
35857 if (screen >= 0x80)
6451
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 431 times.
907 loadscr_old(orig_destdmap, home_screen, no_x80_dir ? -1 : ldir, origin_screen_overlay);
6452
6453 35857 update_slope_comboposes();
6454 35857 cpos_force_update();
6455 35857 trig_trigger_groups();
6456
6457
2/2
✓ Branch 0 taken 1121662 times.
✓ Branch 1 taken 35857 times.
1157519 for (int index : loadscr_ffc_script_ids_to_remove)
6458 {
6459 // Note: ideally would use "destroySprite", but during scrolling the previous
6460 // screen's FFCs are still accessible (even though only the new screen's FFC scripts run).
6461 // The only difference is a call to "release_sprite_owned_objects". To defer FFC script
6462 // owned objects being released until the end of the scroll, here "destroyScriptableObject"
6463 // is used instead.
6464 //
6465 // So when is "release_sprite_owned_objects" called for FFCs? For scrolling screen
6466 // transitions, it's at the end of "scrollscr" via "delete_temporary_screens". Otherwise,
6467 // it is called above when "load_region" calls "clear_temporary_screens".
6468 1121662 FFCore.destroyScriptableObject(ScriptType::FFC, index);
6469 }
6470
6471 // "extended height mode" includes the top 56 pixels as part of the visible mapscr viewport,
6472 // allowing for regions to display 4 more rows of combos (as many as ALTTP does). This part of
6473 // screen is normally reserved for the passive subscreen, but in this mode mapscr combos are drawn below it.
6474 // It is up to the quest designer to make their subscreen be actually transparent.
6475 //
6476 // When not in "extended height mode" (otherwise 56 is 0):
6477 // - playing_field_offset: 56, but changes during earthquakes
6478 // - original_playing_field_offset: always 56
6479 //
6480 // These values are used to adjust where things are drawn on screen to account for the passive subscreen. Examples:
6481 // - yofs of sprites
6482 // - bitmap y offsets in draw_screen
6483 // - drawing offsets for putscr, do_layer
6484 // - drawing offsets for various calls to overtile16 (see bomb weapon explosion)
6485 // - lots more
6486 //
6487 // TODO: consider refactor of yofs, make yofs start as 0 by default and add playing_field_offset at draw time?
6488
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 35715 times.
35857 if (is_extended_height_mode())
6489 {
6490 142 playing_field_offset = 0;
6491 142 original_playing_field_offset = 0;
6492 // A few sprites exist as globals, so we must manually reset them.
6493 142 Hero.yofs = 0;
6494 142 mblock2.yofs = 0;
6495 142 }
6496 else
6497 {
6498 35715 mblock2.yofs = Hero.yofs = playing_field_offset = 56;
6499 35715 original_playing_field_offset = 56;
6500 }
6501 35857 is_any_room_dark = is_any_dark();
6502
6503 35857 game->load_portal();
6504 35857 throwGenScriptEvent(GENSCR_EVENT_CHANGE_SCREEN);
6505
3/4
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 35822 times.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
35857 if (Hero.lift_wpn && get_qr(qr_CARRYABLE_NO_ACROSS_SCREEN))
6506 {
6507 delete Hero.lift_wpn;
6508 Hero.lift_wpn = nullptr;
6509 }
6510
6511 35857 enemy_spawning_has_checked_been_here = false;
6512 35857 markBmap(-1, Hero.current_screen);
6513 35857 Hero.maybe_begin_advanced_maze();
6514 35857 }
6515
6516 // Don't use this directly! Use `loadscr` instead.
6517 907 void loadscr_old(int32_t destdmap, int32_t screen,int32_t ldir,bool overlay)
6518 {
6519
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 int32_t destlvl = DMaps[destdmap < 0 ? cur_dmap : destdmap].level;
6520
6521 907 mapscr previous_scr = *special_warp_return_scr;
6522 907 mapscr* scr = special_warp_return_scr;
6523
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 const mapscr* source = get_canonical_scr(cur_map, screen);
6524
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 *scr = *source;
6525
6526
2/2
✓ Branch 0 taken 5442 times.
✓ Branch 1 taken 907 times.
6349 for (int i = 1; i <= 6; i++)
6527 {
6528
2/2
✓ Branch 0 taken 5059 times.
✓ Branch 1 taken 383 times.
5442 if (scr->layermap[i-1] > 0)
6529
2/4
✓ Branch 0 taken 383 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 383 times.
✗ Branch 3 not taken.
383 special_warp_return_scrs[i] = *get_canonical_scr(scr->layermap[i-1] - 1, scr->layerscreen[i-1]);
6530 else
6531
2/4
✓ Branch 0 taken 5059 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5059 times.
✗ Branch 3 not taken.
5059 special_warp_return_scrs[i] = {};
6532 5442 }
6533
6534 907 scr->valid |= mVALID; //layer 0 is always valid
6535
6536
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 907 times.
907 if ( source->script > 0 )
6537 {
6538 scr->script = source->script;
6539 for ( int32_t q = 0; q < 8; q++ )
6540 {
6541 scr->screeninitd[q] = source->screeninitd[q];
6542 }
6543 FFCore.reset_script_engine_data(ScriptType::Screen, screen);
6544 }
6545 else
6546 {
6547 907 scr->script = 0;
6548 }
6549
6550
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 if(overlay)
6551 {
6552 for(int32_t c=0; c< 176; ++c)
6553 {
6554 if(scr->data[c]==0)
6555 {
6556 scr->data[c]=previous_scr.data[c];
6557 scr->sflag[c]=previous_scr.sflag[c];
6558 scr->cset[c]=previous_scr.cset[c];
6559 }
6560 }
6561
6562 for(int32_t i=0; i<6; i++)
6563 {
6564 if(previous_scr.layermap[i]>0 && scr->layermap[i]>0)
6565 {
6566 int32_t lm = (scr->layermap[i]-1)*MAPSCRS+scr->layerscreen[i];
6567 int32_t fm = (previous_scr.layermap[i]-1)*MAPSCRS+previous_scr.layerscreen[i];
6568
6569 for(int32_t c=0; c< 176; ++c)
6570 {
6571 if(TheMaps[lm].data[c]==0)
6572 {
6573 TheMaps[lm].data[c] = TheMaps[fm].data[c];
6574 TheMaps[lm].sflag[c] = TheMaps[fm].sflag[c];
6575 TheMaps[lm].cset[c] = TheMaps[fm].cset[c];
6576 }
6577 }
6578 }
6579 }
6580 }
6581
6582
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
29900 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
6583
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 int c = scr->numFFC();
6584
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 28993 times.
29900 for (word i = 0; i < c; i++)
6585 {
6586 28993 scr->ffcs[i].screen_spawned = screen;
6587
1/2
✓ Branch 0 taken 28993 times.
✗ Branch 1 not taken.
28993 scr->ffcs[i].x += offx;
6588
1/2
✓ Branch 0 taken 28993 times.
✗ Branch 1 not taken.
28993 scr->ffcs[i].y += offy;
6589 28993 }
6590
6591 907 int mi = mapind(cur_map, screen);
6592
6593 // Apply perm secrets, if applicable.
6594
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 536 times.
✓ Branch 3 taken 371 times.
907 if(canPermSecret(destdmap,screen))
6595 {
6596
3/4
✓ Branch 0 taken 536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 204 times.
✓ Branch 3 taken 332 times.
536 if(game->maps[mi]&mSECRET) // if special stuff done before
6597 {
6598
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 reveal_hidden_stairs(scr, screen, false);
6599
6600
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 log_trigger_secret_reason(TriggerSource::SecretsScreenState);
6601
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 get_screen_state(special_warp_return_scr->screen).triggered_secrets = true;
6602 204 bool do_replay_comment = true;
6603 204 bool from_active_screen = false;
6604
2/4
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 204 times.
✗ Branch 3 not taken.
204 trigger_secrets_for_screen_internal(create_screen_handles(special_warp_return_scr), from_active_screen, false, -1, do_replay_comment);
6605 204 }
6606
2/4
✓ Branch 0 taken 536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 536 times.
✗ Branch 3 not taken.
536 if(game->maps[mi]&mLIGHTBEAM) // if special stuff done before
6607 {
6608 for (int layer = 0; layer <= 6; layer++)
6609 {
6610 mapscr* tscr = &special_warp_return_scrs[layer];
6611 for (int pos = 0; pos < 176; pos++)
6612 {
6613 newcombo const* cmb = &combobuf[tscr->data[pos]];
6614 if(cmb->type == cLIGHTTARGET)
6615 {
6616 if(!(cmb->usrflags&cflag1)) //Unlit version
6617 {
6618 tscr->data[pos] += 1;
6619 }
6620 }
6621 }
6622 }
6623 }
6624 536 }
6625
6626 screen_handles_t screen_handles;
6627
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 6349 times.
7256 for (int i = 0; i <= 6; i++)
6628
3/4
✓ Branch 0 taken 6349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1284 times.
✓ Branch 3 taken 5065 times.
6349 screen_handles[i] = {scr, special_warp_return_scrs[i].is_valid() ? &special_warp_return_scrs[i] : nullptr, screen, i};
6629
6630
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 907 times.
✗ Branch 3 not taken.
907 toggle_switches(game->lvlswitches[destlvl], true, screen_handles);
6631
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 toggle_gswitches_load(screen_handles);
6632
6633
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 902 times.
907 if(game->maps[mi]&mLOCKBLOCK) // if special stuff done before
6634 {
6635
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 remove_lockblocks(screen_handles);
6636 5 }
6637
6638
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 906 times.
907 if(game->maps[mi]&mBOSSLOCKBLOCK) // if special stuff done before
6639 {
6640
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 remove_bosslockblocks(screen_handles);
6641 1 }
6642
6643
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 907 times.
907 if(game->maps[mi]&mCHEST) // if special stuff done before
6644 {
6645 remove_chests(screen_handles);
6646 }
6647
6648
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 907 times.
907 if(game->maps[mi]&mLOCKEDCHEST) // if special stuff done before
6649 {
6650 remove_lockedchests(screen_handles);
6651 }
6652
6653
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 907 times.
907 if(game->maps[mi]&mBOSSCHEST) // if special stuff done before
6654 {
6655 remove_bosschests(screen_handles);
6656 }
6657
6658
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 clear_xdoors(screen_handles, true);
6659
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 clear_xstatecombos(screen_handles, true);
6660
6661 // check doors
6662
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 536 times.
✓ Branch 3 taken 371 times.
907 if (isdungeon(destdmap, screen))
6663 {
6664
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 371 times.
1855 for(int32_t i=0; i<4; i++)
6665 {
6666 1484 int32_t door=scr->door[i];
6667
6668
4/5
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 89 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1295 times.
1484 switch(door)
6669 {
6670 case d1WAYSHUTTER:
6671 case dSHUTTER:
6672 if ((ldir^1)==i && screen == home_screen)
6673 {
6674 scr->door[i]=dOPENSHUTTER;
6675 }
6676
6677 get_screen_state(screen).open_doors = -4;
6678 105 break;
6679
6680 case dLOCKED:
6681
3/4
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 80 times.
91 if(game->maps[mi]&(mDOOR_UP<<i))
6682 {
6683 80 scr->door[i]=dUNLOCKED;
6684 80 }
6685
6686 91 break;
6687
6688 case dBOSS:
6689
3/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 5 times.
9 if(game->maps[mi]&(mDOOR_UP<<i))
6690 {
6691 5 scr->door[i]=dOPENBOSS;
6692 5 }
6693
6694 9 break;
6695
6696 case dBOMB:
6697
3/4
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✓ Branch 3 taken 51 times.
89 if(game->maps[mi]&(mDOOR_UP<<i))
6698 {
6699 51 scr->door[i]=dBOMBED;
6700 51 }
6701
6702 89 break;
6703 }
6704
6705
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 105 times.
1589 update_door(scr, i, scr->door[i]);
6706
6707
4/4
✓ Branch 0 taken 1390 times.
✓ Branch 1 taken 94 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 1379 times.
1484 if(door==dSHUTTER||door==d1WAYSHUTTER)
6708 {
6709 105 scr->door[i]=door;
6710 105 }
6711 1484 }
6712 371 }
6713
6714
2/2
✓ Branch 0 taken 6139 times.
✓ Branch 1 taken 1117 times.
7256 for(int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6715 {
6716
4/4
✓ Branch 0 taken 5442 times.
✓ Branch 1 taken 697 times.
✓ Branch 2 taken 593 times.
✓ Branch 3 taken 4849 times.
6139 if (j<0 || scr->layermap[j] > 0)
6717 {
6718
4/4
✓ Branch 0 taken 383 times.
✓ Branch 1 taken 907 times.
✓ Branch 2 taken 382 times.
✓ Branch 3 taken 1 times.
1290 mapscr *layerscreen= (j<0 ? scr : special_warp_return_scrs[j+1].valid ? &special_warp_return_scrs[j+1] :
6719 1 &TheMaps[(scr->layermap[j]-1)*MAPSCRS]+scr->layerscreen[j]);
6720
6721
2/2
✓ Branch 0 taken 226830 times.
✓ Branch 1 taken 1500 times.
228330 for(int32_t i=0; i<176; ++i)
6722 {
6723 226830 int32_t c=layerscreen->data[i];
6724
6725 // New screen flag: Cycle Combos At Screen Init
6726
5/8
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 226824 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 210 times.
✓ Branch 7 taken 210 times.
226830 if(combobuf[c].nextcombo != 0 && (scr->flags3 & fCYCLEONINIT) && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6727 {
6728 210 int32_t r = 0;
6729
6730
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 210 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
210 while(combobuf[c].can_cycle() && r++ < 10)
6731 {
6732 newcombo const& cmb = combobuf[c];
6733 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6734 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6735 layerscreen->data[i] = cid;
6736 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6737 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6738 c = layerscreen->data[i];
6739 }
6740 }
6741 227040 }
6742 1500 }
6743 6349 }
6744 1537 }
6745
6746 // Load screen (and layers). Unlike loadscr, this doesn't load to the global temporary_screens, but
6747 // instead returns an array of mapscr.
6748 // Used to draw/save the map.
6749 45680 std::array<mapscr, 7> loadscr2(int32_t screen)
6750 {
6751 45680 std::array<mapscr, 7> scrs;
6752 45680 mapscr* scr = &scrs[0];
6753
6754
2/2
✓ Branch 0 taken 64716181 times.
✓ Branch 1 taken 45680 times.
64761861 for(word x=0; x<animated_combos; x++)
6755 {
6756
2/2
✓ Branch 0 taken 31963685 times.
✓ Branch 1 taken 32752496 times.
64716181 if(combobuf[animated_combo_table4[x][0]].nextcombo!=0)
6757 {
6758 32752496 combobuf[animated_combo_table4[x][0]].aclk=0;
6759 32752496 }
6760 64716181 }
6761
6762
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 const mapscr* source = get_canonical_scr(cur_map, screen);
6763
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if (!source->is_valid())
6764 {
6765 scrs[0].valid = 0;
6766 return scrs;
6767 }
6768
6769
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 *scr = *get_canonical_scr(cur_map, screen);
6770
2/2
✓ Branch 0 taken 274080 times.
✓ Branch 1 taken 45680 times.
319760 for (int i = 1; i <= 6; i++)
6771 {
6772
2/2
✓ Branch 0 taken 209266 times.
✓ Branch 1 taken 64814 times.
274080 if (scr->layermap[i-1] > 0)
6773
2/4
✓ Branch 0 taken 64814 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64814 times.
✗ Branch 3 not taken.
64814 scrs[i] = *get_canonical_scr(scr->layermap[i-1] - 1, scr->layerscreen[i-1]);
6774 else
6775
2/4
✓ Branch 0 taken 209266 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 209266 times.
✗ Branch 3 not taken.
209266 scrs[i] = {};
6776 274080 }
6777
6778 screen_handles_t screen_handles;
6779
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 319760 times.
365440 for (int i = 0; i < 7; i++)
6780
3/4
✓ Branch 0 taken 319760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103061 times.
✓ Branch 3 taken 216699 times.
319760 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
6781
6782 45680 int mi = mapind(cur_map, screen);
6783
6784
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45626 times.
✓ Branch 3 taken 54 times.
45680 if(canPermSecret(-1,screen))
6785 {
6786
3/4
✓ Branch 0 taken 45626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5730 times.
✓ Branch 3 taken 39896 times.
45626 if(game->maps[mi]&mSECRET) // if special stuff done before
6787 {
6788
1/2
✓ Branch 0 taken 5730 times.
✗ Branch 1 not taken.
5730 reveal_hidden_stairs(scr, screen, false);
6789 5730 bool from_active_screen = false;
6790 5730 bool do_replay_comment = true;
6791
1/2
✓ Branch 0 taken 5730 times.
✗ Branch 1 not taken.
5730 trigger_secrets_for_screen_internal(screen_handles, from_active_screen, false, -1, do_replay_comment);
6792 5730 }
6793
3/4
✓ Branch 0 taken 45626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45609 times.
✓ Branch 3 taken 17 times.
45626 if(game->maps[mi]&mLIGHTBEAM) // if special stuff done before
6794 {
6795
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 17 times.
136 for (int layer = 0; layer <= 6; layer++)
6796 {
6797 119 mapscr* tscr = &scrs[layer];
6798
2/2
✓ Branch 0 taken 20944 times.
✓ Branch 1 taken 119 times.
21063 for (int pos = 0; pos < 176; pos++)
6799 {
6800 20944 newcombo const* cmb = &combobuf[tscr->data[pos]];
6801
2/2
✓ Branch 0 taken 20927 times.
✓ Branch 1 taken 17 times.
20944 if(cmb->type == cLIGHTTARGET)
6802 {
6803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if(!(cmb->usrflags&cflag1)) //Unlit version
6804 {
6805 17 tscr->data[pos] += 1;
6806 17 }
6807 17 }
6808 20944 }
6809 119 }
6810 17 }
6811 45626 }
6812
6813
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 233 times.
✓ Branch 3 taken 45447 times.
45680 if(game->maps[mi]&mLOCKBLOCK) // if special stuff done before
6814 {
6815
1/2
✓ Branch 0 taken 233 times.
✗ Branch 1 not taken.
233 remove_lockblocks(screen_handles);
6816 233 }
6817
6818
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 45679 times.
45680 if(game->maps[mi]&mBOSSLOCKBLOCK) // if special stuff done before
6819 {
6820
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 remove_bosslockblocks(screen_handles);
6821 1 }
6822
6823
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101 times.
✓ Branch 3 taken 45579 times.
45680 if(game->maps[mi]&mCHEST) // if special stuff done before
6824 {
6825
1/2
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
101 remove_chests(screen_handles);
6826 101 }
6827
6828
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 45656 times.
45680 if(game->maps[mi]&mLOCKEDCHEST) // if special stuff done before
6829 {
6830
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 remove_lockedchests(screen_handles);
6831 24 }
6832
6833
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45680 times.
45680 if(game->maps[mi]&mBOSSCHEST) // if special stuff done before
6834 {
6835 remove_bosschests(screen_handles);
6836 }
6837
6838
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 clear_xdoors(screen_handles);
6839
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 clear_xstatecombos(screen_handles);
6840
6841 // check doors
6842
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45626 times.
✓ Branch 3 taken 54 times.
45680 if (isdungeon(screen))
6843 {
6844
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 54 times.
270 for(int32_t i=0; i<4; i++)
6845 {
6846 216 int32_t door=scr->door[i];
6847 216 bool putit=true;
6848
6849
4/5
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 61 times.
✓ Branch 4 taken 139 times.
216 switch(door)
6850 {
6851 case d1WAYSHUTTER:
6852 case dSHUTTER:
6853 61 break;
6854
6855 case dLOCKED:
6856
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if(game->maps[mi]&(mDOOR_UP<<i))
6857 {
6858 12 scr->door[i]=dUNLOCKED;
6859 12 }
6860
6861 12 break;
6862
6863 case dBOSS:
6864
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if(game->maps[mi]&(mDOOR_UP<<i))
6865 {
6866 scr->door[i]=dOPENBOSS;
6867 }
6868
6869 4 break;
6870
6871 case dBOMB:
6872 if(game->maps[mi]&(mDOOR_UP<<i))
6873 {
6874 scr->door[i]=dBOMBED;
6875 }
6876
6877 break;
6878 }
6879
6880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if(putit)
6881 {
6882
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 putdoor(scr, scrollbuf, i, scr->door[i], false);
6883 216 }
6884
6885
3/4
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 61 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 155 times.
216 if(door==dSHUTTER||door==d1WAYSHUTTER)
6886 {
6887 61 scr->door[i]=door;
6888 61 }
6889 216 }
6890 54 }
6891
6892
2/2
✓ Branch 0 taken 319760 times.
✓ Branch 1 taken 45680 times.
365440 for(int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6893 {
6894
4/4
✓ Branch 0 taken 274080 times.
✓ Branch 1 taken 45680 times.
✓ Branch 2 taken 64814 times.
✓ Branch 3 taken 209266 times.
319760 if (j < 0 || scr->layermap[j] > 0)
6895 {
6896
2/2
✓ Branch 0 taken 64814 times.
✓ Branch 1 taken 45680 times.
110494 mapscr *layerscreen= (j<0 ? scr
6897 64814 : &(TheMaps[(scr->layermap[j]-1)*MAPSCRS+scr->layerscreen[j]]));
6898
6899
2/2
✓ Branch 0 taken 19446944 times.
✓ Branch 1 taken 110494 times.
19557438 for(int32_t i=0; i<176; ++i)
6900 {
6901 19446944 int32_t c=layerscreen->data[i];
6902
6903 // New screen flag: Cycle Combos At Screen Init
6904
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19446944 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
19446944 if((scr->flags3 & fCYCLEONINIT) && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6905 {
6906 int32_t r = 0;
6907
6908 while(combobuf[c].can_cycle() && r++ < 10)
6909 {
6910 newcombo const& cmb = combobuf[c];
6911 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6912 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6913 layerscreen->data[i] = cid;
6914 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6915 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6916 c = layerscreen->data[i];
6917 }
6918 }
6919 19446944 }
6920 110494 }
6921 319760 }
6922
6923 45680 return scrs;
6924
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 }
6925
6926 19021535 void putscr(mapscr* scr, BITMAP* dest, int32_t x, int32_t y)
6927 {
6928 // This is a bogus value while screenscrolling == true, but that's ok
6929 // because it is only used to calculate the rpos, and during screenscrolling
6930 // only the modulus to get pos (draw_cmb_pos does RPOS_TO_POS) is needed, which
6931 // is always the same no matter the value of scr.
6932 19021535 int screen = get_screen_for_world_xy(x, y);
6933
6934 19021535 x -= viewport.x;
6935 19021535 y -= viewport.y;
6936
6937
3/6
✓ Branch 0 taken 19021535 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19021535 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19021535 times.
19021535 if (!scr->is_valid()||!show_layers[0]||scr->hidelayers & 1)
6938 {
6939 rectfill(dest,x,y,x+255,y+175,0);
6940 return;
6941 }
6942
6943 37914161 bool over = XOR(scr->flags7&fLAYER2BG,DMaps[cur_dmap].flags&dmfLAYER2BG)
6944
2/2
✓ Branch 0 taken 18892626 times.
✓ Branch 1 taken 128909 times.
19021535 || XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)
6945
2/2
✓ Branch 0 taken 66419 times.
✓ Branch 1 taken 18826207 times.
18892626 || !get_qr(qr_CLASSIC_DRAWING_ORDER);
6946
6947 int start_x, end_x, start_y, end_y;
6948 19021535 get_bounds_for_draw_cmb_calls(dest, x, y, start_x, end_x, start_y, end_y);
6949
2/2
✓ Branch 0 taken 19021535 times.
✓ Branch 1 taken 202609372 times.
221630907 for (int cy = start_y; cy < end_y; cy++)
6950 {
6951
2/2
✓ Branch 0 taken 3076800146 times.
✓ Branch 1 taken 202609372 times.
3279409518 for (int cx = start_x; cx < end_x; cx++)
6952 {
6953 3076800146 int i = cx + cy*16;
6954
2/2
✓ Branch 0 taken 357850966 times.
✓ Branch 1 taken 2718949180 times.
3076800146 auto rpos = screenscrolling ? rpos_t::None : POS_TO_RPOS(i, screen);
6955 3076800146 draw_cmb_pos(dest, x + cx*16, y + cy*16, rpos, scr->data[i], scr->cset[i], 0, over, false);
6956 3076800146 }
6957 202609372 }
6958 19021535 }
6959
6960 15545248 static void putscrdoors(const nearby_screens_t& nearby_screens, BITMAP *dest, int32_t x, int32_t y)
6961 {
6962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15545248 times.
15545248 if (!show_layers[0])
6963 {
6964 return;
6965 }
6966
6967 15545248 x -= viewport.x;
6968 15545248 y -= viewport.y;
6969
6970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15545248 times.
31226814 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
6971 15681566 mapscr* scr = screen_handles[0].base_scr;
6972
1/2
✓ Branch 0 taken 15681566 times.
✗ Branch 1 not taken.
15681566 if (!scr->is_valid())
6973 return;
6974
6975
2/2
✓ Branch 0 taken 123411 times.
✓ Branch 1 taken 15558155 times.
15681566 if(scr->door[0]==dBOMBED)
6976 {
6977 123411 over_door(scr, dest, 39, up, offx+x, offy+y);
6978 123411 }
6979
6980
2/2
✓ Branch 0 taken 143109 times.
✓ Branch 1 taken 15538457 times.
15681566 if(scr->door[1]==dBOMBED)
6981 {
6982 143109 over_door(scr, dest, 135, down, offx+x, offy+y);
6983 143109 }
6984
6985
2/2
✓ Branch 0 taken 155862 times.
✓ Branch 1 taken 15525704 times.
15681566 if(scr->door[2]==dBOMBED)
6986 {
6987 155862 over_door(scr, dest, 66, left, offx+x, offy+y);
6988 155862 }
6989
6990
2/2
✓ Branch 0 taken 132289 times.
✓ Branch 1 taken 15549277 times.
15681566 if(scr->door[3]==dBOMBED)
6991 {
6992 132289 over_door(scr, dest, 77, right, offx+x, offy+y);
6993 132289 }
6994 15681566 });
6995 15545248 }
6996
6997 3339969 void putscrdoors(mapscr* scr, BITMAP *dest, int32_t x, int32_t y)
6998 {
6999
2/4
✓ Branch 0 taken 3339969 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3339969 times.
✗ Branch 3 not taken.
3339969 if (!scr->is_valid() || !show_layers[0])
7000 return;
7001
7002 3339969 x -= viewport.x;
7003 3339969 y -= viewport.y;
7004
7005
2/2
✓ Branch 0 taken 37656 times.
✓ Branch 1 taken 3302313 times.
3339969 if(scr->door[0]==dBOMBED)
7006 {
7007 37656 over_door(scr,dest,39,up,x,y);
7008 37656 }
7009
7010
2/2
✓ Branch 0 taken 36495 times.
✓ Branch 1 taken 3303474 times.
3339969 if(scr->door[1]==dBOMBED)
7011 {
7012 36495 over_door(scr,dest,135,down,x,y);
7013 36495 }
7014
7015
2/2
✓ Branch 0 taken 40440 times.
✓ Branch 1 taken 3299529 times.
3339969 if(scr->door[2]==dBOMBED)
7016 {
7017 40440 over_door(scr,dest,66,left,x,y);
7018 40440 }
7019
7020
2/2
✓ Branch 0 taken 37063 times.
✓ Branch 1 taken 3302906 times.
3339969 if(scr->door[3]==dBOMBED)
7021 {
7022 37063 over_door(scr,dest,77,right,x,y);
7023 37063 }
7024 3339969 }
7025 234031097 static inline bool standing_on_z(newcombo const& cmb, zfix const& standing_z_state)
7026 {
7027
1/2
✓ Branch 0 taken 234031097 times.
✗ Branch 1 not taken.
234031097 if (cmb.dive_under_level)
7028 {
7029 if (standing_z_state <= -cmb.dive_under_level)
7030 return true;
7031 }
7032
7033 234031097 zfix cmb_z, cmb_z_step;
7034
4/4
✓ Branch 0 taken 92789 times.
✓ Branch 1 taken 233938308 times.
✓ Branch 2 taken 88819 times.
✓ Branch 3 taken 3970 times.
234031097 if(cmb.type == cCSWITCHBLOCK && (cmb.usrflags & cflag9))
7035 {
7036 3970 cmb_z = zslongToFix(cmb.attributes[2]);
7037
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3970 times.
3970 cmb_z_step = zslongToFix(zc_max(0,cmb.attributes[3]));
7038 3970 }
7039
2/2
✓ Branch 0 taken 1983 times.
✓ Branch 1 taken 234025144 times.
234027127 else if(cmb.genflags & cflag3)
7040 {
7041 1983 cmb_z = cmb.z_height;
7042
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1983 times.
1983 cmb_z_step = zc_max(0_zf,cmb.z_step_height);
7043 1983 }
7044 234025144 else return false;
7045
7046
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5953 times.
5953 if (standing_z_state == STANDING_Z_MAX) // 'infinity'
7047 return true;
7048
2/2
✓ Branch 0 taken 1149 times.
✓ Branch 1 taken 4804 times.
5953 if (!cmb_z) return false; // infinite height
7049
7050 4804 return (cmb_z - cmb_z_step) <= standing_z_state;
7051 234031097 }
7052 56151509 bool _walkflag(zfix_round zx,zfix_round zy,int32_t cnt)
7053 {
7054 56151509 return _walkflag(zx,zy,cnt,0_zf);
7055 }
7056
7057 132960442 bool _walkflag_new(const mapscr* s0, const mapscr* s1, const mapscr* s2, zfix_round zx, zfix_round zy, zfix const& standing_z_state, bool is_temp_screens)
7058 {
7059 132960442 int x = zx.getRound(), y = zy.getRound();
7060 132960442 int pos = COMBOPOS(x % 256, y % 176);
7061 132960442 const newcombo& c = combobuf[s0->data[pos]];
7062 132960442 const newcombo& c1 = combobuf[s1->data[pos]];
7063 132960442 const newcombo& c2 = combobuf[s2->data[pos]];
7064
4/4
✓ Branch 0 taken 130965001 times.
✓ Branch 1 taken 1995441 times.
✓ Branch 2 taken 130955541 times.
✓ Branch 3 taken 9460 times.
266123172 bool dried = (((iswater_type(c.type)) || (iswater_type(c1.type)) ||
7065
4/4
✓ Branch 0 taken 101153 times.
✓ Branch 1 taken 131056676 times.
✓ Branch 2 taken 2101809 times.
✓ Branch 3 taken 4245 times.
132960442 (iswater_type(c2.type))) && DRIEDLAKE);
7066 133162730 int32_t b=1;
7067
2/2
✓ Branch 0 taken 65647549 times.
✓ Branch 1 taken 67515181 times.
133162730 if(x&8) b<<=2;
7068
2/2
✓ Branch 0 taken 62212987 times.
✓ Branch 1 taken 70949743 times.
133162730 if(y&8) b<<=1;
7069
7070 133162730 int32_t cwalkflag = c.walk;
7071
4/4
✓ Branch 0 taken 133061586 times.
✓ Branch 1 taken 101144 times.
✓ Branch 2 taken 133061422 times.
✓ Branch 3 taken 164 times.
133162730 if(is_temp_screens && standing_on_z(c,standing_z_state)) cwalkflag &= (c.walk>>4)^0xF;
7072
8/10
✓ Branch 0 taken 50572 times.
✓ Branch 1 taken 133111994 times.
✓ Branch 2 taken 2096585 times.
✓ Branch 3 taken 2046013 times.
✓ Branch 4 taken 2096585 times.
✓ Branch 5 taken 133061422 times.
✓ Branch 6 taken 2096585 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2096585 times.
✗ Branch 9 not taken.
133162566 else if ((c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) || (iswater_type(c.type) && ((c.walk>>4)&b) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)))) cwalkflag = 0;
7073
2/2
✓ Branch 0 taken 63211281 times.
✓ Branch 1 taken 69850305 times.
133061586 if (s1 != s0)
7074 {
7075
3/4
✓ Branch 0 taken 69850305 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69849687 times.
✓ Branch 3 taken 618 times.
69850305 if(is_temp_screens && standing_on_z(c1,standing_z_state)) cwalkflag &= (c1.walk>>4)^0xF;
7076
4/10
✓ Branch 0 taken 11729 times.
✓ Branch 1 taken 69837958 times.
✓ Branch 2 taken 11729 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11729 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
69849687 else if ((iswater_type(c1.type) && ((c1.walk>>4)&b) && get_qr(qr_WATER_ON_LAYER_1) && !((c1.usrflags&cflag3) || (c1.usrflags&cflag4)))) cwalkflag &= c1.walk;
7077
2/2
✓ Branch 0 taken 62906 times.
✓ Branch 1 taken 69786781 times.
69849687 else if (c1.type == cBRIDGE)
7078 {
7079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62906 times.
62906 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
7080 {
7081 62906 int efflag = (c1.walk & 0xF0)>>4;
7082 62906 int newsolid = (c1.walk & 0xF);
7083 62906 cwalkflag = ((newsolid | cwalkflag) & (~efflag)) | (newsolid & efflag);
7084 62906 }
7085 else cwalkflag &= c1.walk;
7086 62906 }
7087
3/8
✓ Branch 0 taken 11729 times.
✓ Branch 1 taken 69775052 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11729 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
69786781 else if ((iswater_type(c1.type) && get_qr(qr_WATER_ON_LAYER_1) && ((c1.usrflags&cflag3) || (c1.usrflags&cflag4)) && ((c1.walk>>4)&b))) cwalkflag = 0;
7088 69786781 else cwalkflag |= c1.walk;
7089 69850305 }
7090
2/2
✓ Branch 0 taken 101942380 times.
✓ Branch 1 taken 31119206 times.
133061586 if (s2 != s0)
7091 {
7092
2/4
✓ Branch 0 taken 31119206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31119206 times.
✗ Branch 3 not taken.
31119206 if(is_temp_screens && standing_on_z(c2,standing_z_state)) cwalkflag &= (c2.walk>>4)^0xF;
7093
4/10
✓ Branch 0 taken 2154 times.
✓ Branch 1 taken 31117052 times.
✓ Branch 2 taken 2154 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2154 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
31119206 else if ((iswater_type(c2.type) && ((c2.walk>>4)&b) && get_qr(qr_WATER_ON_LAYER_2) && !((c2.usrflags&cflag3) || (c2.usrflags&cflag4)))) cwalkflag &= c2.walk;
7094
2/2
✓ Branch 0 taken 4447 times.
✓ Branch 1 taken 31114759 times.
31119206 else if (c2.type == cBRIDGE)
7095 {
7096
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4447 times.
4447 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
7097 {
7098 4447 int efflag = (c2.walk & 0xF0)>>4;
7099 4447 int newsolid = (c2.walk & 0xF);
7100 4447 cwalkflag = ((newsolid | cwalkflag) & (~efflag)) | (newsolid & efflag);
7101 4447 }
7102 else cwalkflag &= c2.walk;
7103 4447 }
7104
3/8
✓ Branch 0 taken 2154 times.
✓ Branch 1 taken 31112605 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2154 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
31114759 else if ((iswater_type(c2.type) && get_qr(qr_WATER_ON_LAYER_2) && ((c2.usrflags&cflag3) || (c2.usrflags&cflag4))) && ((c2.walk>>4)&b)) cwalkflag = 0;
7105 31114759 else cwalkflag |= c2.walk;
7106 31119206 }
7107
7108
4/4
✓ Branch 0 taken 29570743 times.
✓ Branch 1 taken 103490843 times.
✓ Branch 2 taken 948 times.
✓ Branch 3 taken 29569795 times.
133061586 if((cwalkflag&b) && !dried)
7109 29569795 return true;
7110
7111
3/4
✓ Branch 0 taken 103491791 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103475380 times.
✓ Branch 3 taken 16411 times.
103491791 if (is_temp_screens && collide_object(zx, zy, 0.0001_zf, 0.0001_zf)) return true;
7112
7113 103475380 return false;
7114 133061586 }
7115
7116 // Returns true if the combo at viewport position x,y is solid. Looks at a combo's quadrant walkablity flags.
7117 133061586 static bool _walkflag_new(zfix_round zx, zfix_round zy, zfix const& standing_z_state)
7118 {
7119 133061586 int x = zx.getRound(), y = zy.getRound();
7120 133061586 mapscr* s0 = get_scr_for_world_xy_layer(x, y, 0);
7121 133061586 mapscr* s1 = get_scr_for_world_xy_layer(x, y, 1);
7122 133061586 mapscr* s2 = get_scr_for_world_xy_layer(x, y, 2);
7123
2/2
✓ Branch 0 taken 63211281 times.
✓ Branch 1 taken 69850305 times.
133061586 if (!s1->valid) s1 = s0;
7124
2/2
✓ Branch 0 taken 101942380 times.
✓ Branch 1 taken 31119206 times.
133061586 if (!s2->valid) s2 = s0;
7125 133061586 return _walkflag_new(s0, s1, s2, zx, zy, standing_z_state, true);
7126 }
7127
7128 128627771 bool _walkflag(zfix_round x,zfix_round y,int32_t cnt,zfix const& standing_z_state)
7129 {
7130 128627771 int max_x = world_w;
7131 128627771 int max_y = world_h;
7132
2/2
✓ Branch 0 taken 68585034 times.
✓ Branch 1 taken 60042737 times.
128627771 if (!get_qr(qr_LTTPWALK))
7133 {
7134 60042737 max_x -= 7;
7135 60042737 max_y -= 7;
7136 60042737 }
7137
4/4
✓ Branch 0 taken 128356939 times.
✓ Branch 1 taken 270832 times.
✓ Branch 2 taken 83268 times.
✓ Branch 3 taken 128273671 times.
128627771 if (x < 0 || y < 0) return false;
7138
2/2
✓ Branch 0 taken 322356 times.
✓ Branch 1 taken 127951315 times.
128273671 if (x >= max_x) return false;
7139
3/4
✓ Branch 0 taken 539693 times.
✓ Branch 1 taken 127411622 times.
✓ Branch 2 taken 539693 times.
✗ Branch 3 not taken.
127951315 if (x >= max_x - 8 && cnt == 2) return false;
7140
2/2
✓ Branch 0 taken 127402091 times.
✓ Branch 1 taken 549224 times.
127951315 if (y >= max_y) return false;
7141
7142
4/4
✓ Branch 0 taken 29468053 times.
✓ Branch 1 taken 97934038 times.
✓ Branch 2 taken 92274543 times.
✓ Branch 3 taken 5659495 times.
127402091 return _walkflag_new(x, y, standing_z_state) || (cnt != 1 && _walkflag_new(x + 8, y, standing_z_state));
7143 128627771 }
7144
7145 99195426 static bool effectflag(int32_t x, int32_t y, int32_t layer)
7146 {
7147 99195426 mapscr* s0 = get_scr_for_world_xy(x, y);
7148 99195426 mapscr* s1 = get_scr_for_world_xy_layer(x, y, 1);
7149 99195426 mapscr* s2 = get_scr_for_world_xy_layer(x, y, 2);
7150
2/2
✓ Branch 0 taken 51727123 times.
✓ Branch 1 taken 47468303 times.
99195426 if (!s1->valid) s1 = s0;
7151
2/2
✓ Branch 0 taken 18770050 times.
✓ Branch 1 taken 80425376 times.
99195426 if (!s2->valid) s2 = s0;
7152
7153 99195426 int pos = COMBOPOS(x % 256, y % 176);
7154 99195426 const newcombo& c = combobuf[s0->data[pos]];
7155 99195426 const newcombo& c1 = combobuf[s1->data[pos]];
7156 99195426 const newcombo& c2 = combobuf[s2->data[pos]];
7157
4/4
✓ Branch 0 taken 98270387 times.
✓ Branch 1 taken 925039 times.
✓ Branch 2 taken 98269107 times.
✓ Branch 3 taken 1280 times.
198390852 bool dried = (((iswater_type(c.type)) || (iswater_type(c1.type)) ||
7158
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 98269107 times.
✓ Branch 2 taken 924635 times.
✓ Branch 3 taken 1684 times.
99195426 (iswater_type(c2.type))) && DRIEDLAKE);
7159 99195426 int32_t b=1;
7160
2/2
✓ Branch 0 taken 50195908 times.
✓ Branch 1 taken 48999518 times.
99195426 if(x&8) b<<=2;
7161
2/2
✓ Branch 0 taken 41928447 times.
✓ Branch 1 taken 57266979 times.
99195426 if(y&8) b<<=1;
7162
7163 99195426 int32_t cwalkflag = (c.walk>>4);
7164
2/2
✓ Branch 0 taken 76385093 times.
✓ Branch 1 taken 22810333 times.
99195426 if (layer == 0) cwalkflag = (c1.walk>>4);
7165
2/2
✓ Branch 0 taken 76386291 times.
✓ Branch 1 taken 22809135 times.
99195426 if (layer == 1) cwalkflag = (c2.walk>>4);
7166 //if (c.type == cBRIDGE || (iswater_type(c.type) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)))) cwalkflag = 0;
7167
4/4
✓ Branch 0 taken 51727123 times.
✓ Branch 1 taken 47468303 times.
✓ Branch 2 taken 22541940 times.
✓ Branch 3 taken 29185183 times.
99195426 if (s1 != s0 && layer < 0)
7168 {
7169
2/2
✓ Branch 0 taken 22528434 times.
✓ Branch 1 taken 13506 times.
22541940 if (c1.type == cBRIDGE) cwalkflag &= (~(c1.walk>>4));
7170 22541940 }
7171
4/4
✓ Branch 0 taken 18770050 times.
✓ Branch 1 taken 80425376 times.
✓ Branch 2 taken 13845049 times.
✓ Branch 3 taken 4925001 times.
99195426 if (s2 != s0 && layer < 1)
7172 {
7173
2/2
✓ Branch 0 taken 13839189 times.
✓ Branch 1 taken 5860 times.
13845049 if (c2.type == cBRIDGE) cwalkflag &= (~(c2.walk>>4));
7174 13845049 }
7175
7176
2/2
✓ Branch 0 taken 99026154 times.
✓ Branch 1 taken 169272 times.
99195426 return (cwalkflag&b) ? !dried : false;
7177 }
7178
7179 99568750 bool _effectflag(int32_t x,int32_t y,int32_t cnt, int32_t layer, bool notLink)
7180 {
7181 DCHECK(cnt == 0 || cnt == 1);
7182 99568750 int max_x = world_w;
7183 99568750 int max_y = world_h;
7184
3/4
✓ Branch 0 taken 45833723 times.
✓ Branch 1 taken 53735027 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45833723 times.
99568750 if (!get_qr(qr_LTTPWALK) && !notLink)
7185 {
7186 45833723 max_x -= 7;
7187 45833723 max_y -= 7;
7188 45833723 }
7189
4/4
✓ Branch 0 taken 99567998 times.
✓ Branch 1 taken 752 times.
✓ Branch 2 taken 204 times.
✓ Branch 3 taken 99567794 times.
99568750 if (x < 0 || y < 0) return false;
7190
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 99566978 times.
99567794 if (x >= max_x) return false;
7191
3/4
✓ Branch 0 taken 520208 times.
✓ Branch 1 taken 99046770 times.
✓ Branch 2 taken 520208 times.
✗ Branch 3 not taken.
99566978 if (x >= max_x - 8 && cnt == 2) return false;
7192
2/2
✓ Branch 0 taken 371552 times.
✓ Branch 1 taken 99195426 times.
99566978 if (y >= max_y) return false;
7193
7194
3/4
✓ Branch 0 taken 99025364 times.
✓ Branch 1 taken 170062 times.
✓ Branch 2 taken 170062 times.
✗ Branch 3 not taken.
99195426 return effectflag(x, y, layer) || (cnt == 2 && effectflag(x + 8, y, layer));
7195 99568750 }
7196
7197 // used by mapdata->isSolid(x,y) in ZScript
7198 bool _walkflag(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
7199 {
7200 int x = zx.getRound(), y = zy.getRound();
7201 {
7202 int max_x = 256;
7203 int max_y = 176;
7204 if (!get_qr(qr_LTTPWALK))
7205 {
7206 max_x -= 7;
7207 max_y -= 7;
7208 }
7209 if (x < 0 || y < 0) return false;
7210 if (x >= max_x) return false;
7211 if (x >= max_x - 8 && cnt == 2) return false;
7212 if (y >= max_y) return false;
7213 }
7214
7215 const mapscr *s1, *s2;
7216
7217 if ( m->layermap[0] > 0 )
7218 {
7219 s1 = get_canonical_scr(m->layermap[0], m->layerscreen[0]);
7220 }
7221 else s1 = m;
7222
7223 if ( m->layermap[1] > 0 )
7224 {
7225 s2 = get_canonical_scr(m->layermap[1], m->layerscreen[1]);
7226 }
7227 else s2 = m;
7228
7229 zfix unused;
7230 return _walkflag_new(m, s1, s2, x, y, unused, false) || (cnt != 1 && _walkflag_new(m, s1, s2, x + 8, y, unused, false));
7231 }
7232
7233 bool _walkflag_layer(zfix_round x, zfix_round y, int32_t layer, int32_t cnt)
7234 {
7235 DCHECK_LAYER_NEG1_INDEX(layer);
7236 mapscr* m = get_scr_for_world_xy_layer(x, y, layer + 1);
7237 if (!m->is_valid()) return false;
7238 return _walkflag_layer(x, y, cnt, m);
7239 }
7240
7241 static bool _walkflag_layer_new(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m, int max_x, int max_y)
7242 {
7243 int x = zx.getRound(), y = zy.getRound();
7244
7245 if (!get_qr(qr_LTTPWALK))
7246 {
7247 max_x -= 7;
7248 max_y -= 7;
7249 }
7250 if (x < 0 || y < 0) return false;
7251 if (x >= max_x) return false;
7252 if (x >= max_x - 8 && cnt == 2) return false;
7253 if (y >= max_y) return false;
7254
7255 if(!m) return true;
7256
7257 int pos = COMBOPOS(x%256, y%176);
7258 const newcombo* c = &combobuf[m->data[pos]];
7259 bool dried = ((iswater_type(c->type)) && DRIEDLAKE);
7260 int32_t b=1;
7261
7262 if(x&8) b<<=2;
7263
7264 if(y&8) b<<=1;
7265
7266 if((c->walk&b) && !dried)
7267 return true;
7268
7269 if(cnt==1) return false;
7270
7271 ++pos;
7272
7273 if(!(x&8))
7274 b<<=2;
7275 else
7276 {
7277 c = &combobuf[m->data[pos]];
7278 dried = ((iswater_type(c->type)) && DRIEDLAKE);
7279 b=1;
7280
7281 if(y&8) b<<=1;
7282 }
7283
7284 return (c->walk&b) ? !dried : false;
7285 }
7286
7287 //Only check the given mapscr*, not its layer 1&2
7288 bool _walkflag_layer(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
7289 {
7290 return _walkflag_layer_new(zx, zy, cnt, m, world_w, world_h);
7291 }
7292
7293 bool _walkflag_layer_scrolling(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
7294 {
7295 return _walkflag_layer_new(zx, zy, cnt, m, scrolling_region.width, scrolling_region.height);
7296 }
7297
7298 313631 bool _effectflag_layer(int32_t x, int32_t y, int32_t layer, int32_t cnt, bool notLink)
7299 {
7300 DCHECK_LAYER_NEG1_INDEX(layer);
7301 313631 mapscr* m = get_scr_for_world_xy_layer(x, y, layer + 1);
7302
2/2
✓ Branch 0 taken 1762 times.
✓ Branch 1 taken 311869 times.
313631 if (!m->is_valid()) return false;
7303 311869 return _effectflag_layer(x, y, cnt, m, notLink);
7304 313631 }
7305
7306 377902 bool _effectflag_layer(int32_t x,int32_t y,int32_t cnt, mapscr* m, bool notLink)
7307 {
7308 377902 int max_x = world_w;
7309 377902 int max_y = world_h;
7310
3/4
✓ Branch 0 taken 50002 times.
✓ Branch 1 taken 327900 times.
✓ Branch 2 taken 50002 times.
✗ Branch 3 not taken.
377902 if (!get_qr(qr_LTTPWALK) && !notLink)
7311 {
7312 max_x -= 7;
7313 max_y -= 7;
7314 }
7315
2/4
✓ Branch 0 taken 377902 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 377902 times.
377902 if (x < 0 || y < 0) return false;
7316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 377902 times.
377902 if (x >= max_x) return false;
7317
3/4
✓ Branch 0 taken 1209 times.
✓ Branch 1 taken 376693 times.
✓ Branch 2 taken 1209 times.
✗ Branch 3 not taken.
377902 if (x >= max_x - 8 && cnt == 2) return false;
7318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 377902 times.
377902 if (y >= max_y) return false;
7319
7320
1/2
✓ Branch 0 taken 377902 times.
✗ Branch 1 not taken.
377902 if (!m) return true;
7321
7322 377902 int pos = COMBOPOS(x%256, y%176);
7323 377902 const newcombo* c = &combobuf[m->data[pos]];
7324
3/4
✓ Branch 0 taken 377502 times.
✓ Branch 1 taken 400 times.
✓ Branch 2 taken 400 times.
✗ Branch 3 not taken.
378302 bool dried = ((iswater_type(c->type)) && DRIEDLAKE);
7325 377902 int32_t b=1;
7326
7327
2/2
✓ Branch 0 taken 205458 times.
✓ Branch 1 taken 172444 times.
377902 if(x&8) b<<=2;
7328
7329
2/2
✓ Branch 0 taken 157257 times.
✓ Branch 1 taken 220645 times.
377902 if(y&8) b<<=1;
7330
7331
3/4
✓ Branch 0 taken 308913 times.
✓ Branch 1 taken 68989 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 308913 times.
377902 if(((c->walk>>4)&b) && !dried)
7332 308913 return true;
7333
7334
1/2
✓ Branch 0 taken 68989 times.
✗ Branch 1 not taken.
68989 if(cnt==1) return false;
7335
7336 ++pos;
7337
7338 if(!(x&8))
7339 b<<=2;
7340 else
7341 {
7342 c = &combobuf[m->data[pos]];
7343 dried = ((iswater_type(c->type)) && DRIEDLAKE);
7344 b=1;
7345
7346 if(y&8) b<<=1;
7347 }
7348
7349 return ((c->walk>>4)&b) ? !dried : false;
7350 377902 }
7351
7352 812605 bool water_walkflag(int32_t x, int32_t y, int32_t cnt)
7353 {
7354 812605 int max_x = world_w;
7355 812605 int max_y = world_h;
7356
2/2
✓ Branch 0 taken 117367 times.
✓ Branch 1 taken 695238 times.
812605 if (!get_qr(qr_LTTPWALK))
7357 {
7358 695238 max_x -= 7;
7359 695238 max_y -= 7;
7360 695238 }
7361
2/4
✓ Branch 0 taken 812605 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 812605 times.
812605 if (x < 0 || y < 0) return false;
7362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812605 times.
812605 if (x >= max_x) return false;
7363
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 812605 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
812605 if (x >= max_x - 8 && cnt == 2) return false;
7364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812605 times.
812605 if (y >= max_y) return false;
7365
7366
3/4
✓ Branch 0 taken 16825 times.
✓ Branch 1 taken 795780 times.
✓ Branch 2 taken 795780 times.
✗ Branch 3 not taken.
812605 return water_walkflag(x, y) || (cnt != 1 && water_walkflag(x + 8, y));
7367 812605 }
7368
7369 812605 bool water_walkflag(int32_t x, int32_t y)
7370 {
7371 812605 const newcombo& c = combobuf[MAPCOMBO2(-1, x, y)];
7372 812605 const newcombo& c1 = combobuf[MAPCOMBO2(0, x, y)];
7373 812605 const newcombo& c2 = combobuf[MAPCOMBO2(1, x, y)];
7374
7375 812605 int32_t b=1;
7376
2/2
✓ Branch 0 taken 414677 times.
✓ Branch 1 taken 397928 times.
812605 if(x&8) b<<=2;
7377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812605 times.
812605 if(y&8) b<<=1;
7378
7379
2/2
✓ Branch 0 taken 26377 times.
✓ Branch 1 taken 786228 times.
812605 if(get_qr(qr_NO_SOLID_SWIM))
7380 {
7381
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 26245 times.
26377 if(c.walk&b)
7382 132 return true;
7383
7384
2/2
✓ Branch 0 taken 292 times.
✓ Branch 1 taken 25953 times.
26245 if(c1.walk&b)
7385 292 return true;
7386
7387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25953 times.
25953 if(c2.walk&b)
7388 return true;
7389 25953 }
7390 else
7391 {
7392
4/4
✓ Branch 0 taken 36133 times.
✓ Branch 1 taken 750095 times.
✓ Branch 2 taken 19762 times.
✓ Branch 3 taken 16371 times.
786228 if((c.walk&b) && !iswater_type(c.type))
7393 16371 return true;
7394
7395
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 769840 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
769857 if((c1.walk&b) && !iswater_type(c1.type))
7396 17 return true;
7397
7398
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 769827 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
769840 if((c2.walk&b) && !iswater_type(c2.type))
7399 13 return true;
7400 }
7401
7402 795780 return false;
7403 812605 }
7404
7405 565044 bool hit_walkflag(int32_t x,int32_t y,int32_t cnt)
7406 {
7407
2/2
✓ Branch 0 taken 91927 times.
✓ Branch 1 taken 473117 times.
565044 if(dlevel)
7408
8/8
✓ Branch 0 taken 471712 times.
✓ Branch 1 taken 1405 times.
✓ Branch 2 taken 468517 times.
✓ Branch 3 taken 3195 times.
✓ Branch 4 taken 466857 times.
✓ Branch 5 taken 1660 times.
✓ Branch 6 taken 4199 times.
✓ Branch 7 taken 462658 times.
473117 if(x<32 || y<40 || (x+(cnt-1)*8)>=world_w-32 || y>=world_h-32)
7409 10459 return true;
7410
7411
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 554583 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
554585 if(blockpath && y<((get_qr(qr_LTTPCOLLISION))?80:88))
7412 return true;
7413
7414
8/8
✓ Branch 0 taken 554316 times.
✓ Branch 1 taken 269 times.
✓ Branch 2 taken 554083 times.
✓ Branch 3 taken 233 times.
✓ Branch 4 taken 553874 times.
✓ Branch 5 taken 209 times.
✓ Branch 6 taken 346 times.
✓ Branch 7 taken 553528 times.
554585 if(x<16 || y<16 || (x+(cnt-1)*8)>=world_w-16 || y>=world_h-16)
7415 1057 return true;
7416
7417 // for(int32_t i=0; i<4; i++)
7418
4/4
✓ Branch 0 taken 841 times.
✓ Branch 1 taken 552687 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 805 times.
553528 if(mblock2.clk && mblock2.hit(x,y,0,cnt*8,1,16))
7419 36 return true;
7420
7421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 553492 times.
553492 if (collide_object(x, y,cnt*8, 1))
7422 return true;
7423
7424 553492 return _walkflag(x,y,cnt);
7425 565044 }
7426
7427 12110 bool solpush_walkflag(int32_t x, int32_t y, int32_t cnt, solid_object const* ign)
7428 {
7429 // 16 pixel buffer to account for slopes that are on bordering screens.
7430
4/8
✓ Branch 0 taken 12110 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12110 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12110 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12110 times.
12110 if(x<0 || y<0 || x>=world_w+16 || y>=world_h+16)
7431 return true;
7432
7433 // for(int32_t i=0; i<4; i++)
7434
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12110 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12110 if(mblock2.clk && mblock2.hit(x,y,0,cnt*8,1,16))
7435 return true;
7436
7437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12110 times.
12110 if (collide_object(x, y,cnt*8, 1, ign))
7438 return true;
7439
7440 12110 return _walkflag(x,y,cnt);
7441 12110 }
7442
7443 37840 void map_bkgsfx(bool on)
7444 {
7445
2/2
✓ Branch 0 taken 37819 times.
✓ Branch 1 taken 21 times.
37840 if(on)
7446 {
7447 37819 cont_sfx(hero_scr->oceansfx);
7448
7449
4/4
✓ Branch 0 taken 369 times.
✓ Branch 1 taken 37450 times.
✓ Branch 2 taken 315 times.
✓ Branch 3 taken 54 times.
37819 if(hero_scr->bosssfx && !(game->lvlitems[dlevel]&(1 << li_boss_killed)))
7450 315 cont_sfx(hero_scr->bosssfx);
7451 37819 }
7452 else
7453 {
7454 21 adjust_sfx(hero_scr->oceansfx,128,false);
7455 21 adjust_sfx(hero_scr->bosssfx,128,false);
7456
7457
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 21 times.
135 for(int32_t i=0; i<guys.Count(); i++)
7458 {
7459
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 84 times.
114 if(((enemy*)guys.spr(i))->bgsfx)
7460 84 stop_sfx(((enemy*)guys.spr(i))->bgsfx);
7461 114 }
7462 }
7463 37840 }
7464
7465 239 void toggle_switches(dword flags, bool entry)
7466 {
7467
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
239 if(!flags) return; //No flags to toggle
7468
7469 478 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7470 239 toggle_switches(flags, entry, create_screen_handles(scr));
7471 239 });
7472 239 }
7473 53509 void toggle_switches(dword flags, bool entry, const screen_handles_t& screen_handles)
7474 {
7475
2/2
✓ Branch 0 taken 737 times.
✓ Branch 1 taken 52772 times.
53509 if(!flags) return; //No flags to toggle
7476
7477 737 mapscr* m = screen_handles[0].base_scr;
7478 737 int screen = m->screen;
7479 737 bool is_active_screen = is_in_current_region(m);
7480
7481 357489 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
7482 356752 byte togglegrid[176] = {0};
7483 356752 mapscr* scr = rpos_handle.scr;
7484 356752 int lyr = rpos_handle.layer;
7485 356752 int pos = rpos_handle.pos;
7486 356752 newcombo const& cmb = combobuf[scr->data[pos]];
7487
2/2
✓ Branch 0 taken 39424 times.
✓ Branch 1 taken 317328 times.
356752 if(is_active_screen)
7488
1/2
✓ Branch 0 taken 317328 times.
✗ Branch 1 not taken.
472669 trig_each_combo_trigger(rpos_handle, [&](combo_trigger const& trig){
7489
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 155341 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
155341 return trig.trigger_flags.get(TRIGFLAG_TRIGLEVELSTATE) && trig.trig_lstate < 32 && (flags&(1<<trig.trig_lstate));
7490 }, ctrigSWITCHSTATE);
7491
3/4
✓ Branch 0 taken 356089 times.
✓ Branch 1 taken 663 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2760 times.
356752 if((cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && cmb.attribytes[0] < 32
7492
2/2
✓ Branch 0 taken 2760 times.
✓ Branch 1 taken 353992 times.
356752 && !(cmb.usrflags & cflag11)) //global state
7493 {
7494
2/2
✓ Branch 0 taken 446 times.
✓ Branch 1 taken 2314 times.
2760 if(flags&(1<<cmb.attribytes[0]))
7495 {
7496 2314 set<int32_t> oldData;
7497 //Increment the combo/cset by the attributes
7498 2314 int32_t cmbofs = (cmb.attributes[0]/10000L);
7499 2314 int32_t csofs = (cmb.attributes[1]/10000L);
7500
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 oldData.insert(scr->data[pos]);
7501
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 scr->data[pos] = BOUND_COMBO(scr->data[pos] + cmbofs);
7502 2314 scr->cset[pos] = (scr->cset[pos] + csofs) & 15;
7503
4/4
✓ Branch 0 taken 1435 times.
✓ Branch 1 taken 879 times.
✓ Branch 2 taken 1197 times.
✓ Branch 3 taken 238 times.
2314 if(entry && (cmb.usrflags&cflag8))
7504 {
7505 238 newcombo const* tmp = &combobuf[scr->data[pos]];
7506
2/4
✓ Branch 0 taken 238 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 238 times.
✗ Branch 3 not taken.
238 while(tmp->can_cycle())
7507 {
7508 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7509 auto cid = cycle_under ? scr->undercombo : tmp->nextcombo;
7510 if(oldData.find(cid) != oldData.end())
7511 break;
7512
7513 scr->data[pos] = cid;
7514 if(!(tmp->animflags & AF_CYCLENOCSET))
7515 scr->cset[pos] = cycle_under ? scr->undercset : tmp->nextcset;
7516 oldData.insert(cid);
7517 tmp = &combobuf[cid];
7518 }
7519 238 }
7520 2314 int32_t cmbid = scr->data[pos];
7521
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 2273 times.
2314 if(combobuf[cmbid].animflags & AF_CYCLE)
7522 {
7523 41 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7524 41 combobuf[cmbid].cur_frame=0;
7525 41 combobuf[cmbid].aclk = 0;
7526
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 combo_caches::drawing.refresh(cmbid);
7527 41 }
7528 2314 togglegrid[pos] |= (1<<lyr); //Mark this pos toggled for this layer
7529
2/2
✓ Branch 0 taken 511 times.
✓ Branch 1 taken 1803 times.
2314 if(cmb.type == cCSWITCH) return; //Switches don't toggle other layers
7530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2147 times.
2147 for(int32_t lyr2 = 0; lyr2 < 7; ++lyr2) //Toggle same pos on other layers, if flag set
7531 {
7532
2/2
✓ Branch 0 taken 1671 times.
✓ Branch 1 taken 476 times.
2147 if(lyr==lyr2) return;
7533
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 344 times.
476 if(!(cmb.usrflags&(1<<lyr2))) return;
7534
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 if(togglegrid[pos]&(1<<lyr2)) return;
7535
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
344 mapscr* scr_2 = (lyr2 ? get_scr_layer(screen, lyr2) : m);
7536
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 if(!scr_2->data[pos]) //Don't increment empty space
7537 return;
7538 344 newcombo const& cmb_2 = combobuf[scr_2->data[pos]];
7539
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
344 if(lyr2 > lyr && (cmb_2.type == cCSWITCH || cmb_2.type == cCSWITCHBLOCK) && !(cmb.usrflags & cflag11)
7540 && cmb_2.attribytes[0] < 32 && (flags&(1<<cmb_2.attribytes[0])))
7541 return; //This is a switch/block that will be hit later in the loop!
7542 344 set<int32_t> oldData2;
7543 //Increment the combo/cset by the original cmb's attributes
7544
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 oldData2.insert(scr_2->data[pos]);
7545
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 scr_2->data[pos] = BOUND_COMBO(scr_2->data[pos] + cmbofs);
7546 344 scr_2->cset[pos] = (scr_2->cset[pos] + csofs) & 15;
7547
3/4
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 294 times.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
344 if(entry && (cmb.usrflags&cflag8)) //Skip cycling on screen entry
7548 {
7549 newcombo const* tmp = &combobuf[scr_2->data[pos]];
7550 while(tmp->can_cycle())
7551 {
7552 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7553 auto cid = cycle_under ? scr_2->undercombo : tmp->nextcombo;
7554 if(oldData2.find(cid) != oldData2.end())
7555 break;
7556
7557 scr_2->data[pos] = cid;
7558 if(!(tmp->animflags & AF_CYCLENOCSET))
7559 scr_2->cset[pos] = cycle_under ? scr_2->undercset : tmp->nextcset;
7560 oldData2.insert(cid);
7561 tmp = &combobuf[cid];
7562 }
7563 }
7564 344 int32_t cmbid2 = scr_2->data[pos];
7565
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
344 if(combobuf[cmbid2].animflags & AF_CYCLE)
7566 {
7567 combobuf[cmbid2].tile = combobuf[cmbid2].o_tile;
7568 combobuf[cmbid2].cur_frame=0;
7569 combobuf[cmbid2].aclk = 0;
7570 combo_caches::drawing.refresh(cmbid2);
7571 }
7572 344 togglegrid[pos] |= (1<<lyr2); //Mark this pos toggled for this layer
7573 344 }
7574
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 2314 times.
✗ Branch 2 not taken.
2314 }
7575 446 }
7576 356752 });
7577
7578
3/4
✓ Branch 0 taken 519 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 519 times.
✗ Branch 3 not taken.
737 if(get_qr(qr_SWITCHES_AFFECT_MOVINGBLOCKS) && mblock2.clk)
7579 {
7580 newcombo const& cmb = combobuf[mblock2.bcombo];
7581 if(!(cmb.usrflags & cflag11) && (cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && cmb.attribytes[0] < 32)
7582 {
7583 if(flags&(1<<cmb.attribytes[0]))
7584 {
7585 //Increment the combo/cset by the attributes
7586 int32_t cmbofs = (cmb.attributes[0]/10000L);
7587 int32_t csofs = (cmb.attributes[1]/10000L);
7588 mblock2.bcombo = BOUND_COMBO(mblock2.bcombo + cmbofs);
7589 mblock2.cs = (mblock2.cs + csofs) & 15;
7590 int32_t cmbid = mblock2.bcombo;
7591 if(combobuf[cmbid].animflags & AF_CYCLE)
7592 {
7593 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7594 combobuf[cmbid].cur_frame=0;
7595 combobuf[cmbid].aclk = 0;
7596 combo_caches::drawing.refresh(cmbid);
7597 }
7598 }
7599 }
7600 }
7601
7602
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 513 times.
737 if (is_active_screen)
7603 {
7604 513 int screen_index_offset = get_region_screen_offset(m->screen);
7605 513 word c = m->numFFC();
7606
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 513 times.
847 for (int q = 0; q < c; ++q)
7607 {
7608 334 auto ffc_handle = *m->getFFCHandle(q, screen_index_offset);
7609
1/2
✓ Branch 0 taken 334 times.
✗ Branch 1 not taken.
363 trig_each_combo_trigger(ffc_handle, [&](combo_trigger const& trig){
7610
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
29 return trig.trigger_flags.get(TRIGFLAG_TRIGLEVELSTATE) && trig.trig_lstate < 32 && (flags&(1<<trig.trig_lstate));
7611 }, ctrigSWITCHSTATE);
7612 334 }
7613 513 }
7614 53509 }
7615
7616 1 void toggle_gswitches(int32_t state, bool entry)
7617 {
7618 2 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7619 1 toggle_gswitches(state, entry, create_screen_handles(scr));
7620 1 });
7621 1 }
7622 1 void toggle_gswitches(int32_t state, bool entry, const screen_handles_t& screen_handles)
7623 {
7624 1 bool states[256] = {false};
7625 1 states[state] = true;
7626 1 toggle_gswitches(states, entry, screen_handles);
7627 1 }
7628 15221150 void toggle_gswitches(bool* states, bool entry, const screen_handles_t& screen_handles)
7629 {
7630
1/2
✓ Branch 0 taken 15221150 times.
✗ Branch 1 not taken.
15221150 if(!states) return;
7631
7632 15221150 auto& combo_cache = combo_caches::gswitch;
7633 15221150 mapscr* base_scr = screen_handles[0].base_scr;
7634 15221150 int screen = base_scr->screen;
7635 15221150 bool is_active_screen = is_in_current_region(base_scr);
7636 15221150 byte togglegrid[176] = {0};
7637
2/2
✓ Branch 0 taken 15221150 times.
✓ Branch 1 taken 106548050 times.
121769200 for(int32_t lyr = 0; lyr <= 6; ++lyr)
7638 {
7639 106548050 mapscr* scr = screen_handles[lyr].scr;
7640
2/2
✓ Branch 0 taken 33039335 times.
✓ Branch 1 taken 73508715 times.
106548050 if (!scr)
7641 73508715 continue;
7642
7643
2/2
✓ Branch 0 taken 33039335 times.
✓ Branch 1 taken 5814922960 times.
5847962295 for(int32_t pos = 0; pos < 176; ++pos)
7644 {
7645 5814922960 int cid = scr->data[pos];
7646 5814922960 auto& mini_cmb = combo_cache.minis[cid];
7647
7648
2/2
✓ Branch 0 taken 2910336 times.
✓ Branch 1 taken 5812012624 times.
5814922960 if (is_active_screen)
7649 {
7650
2/2
✓ Branch 0 taken 5812010742 times.
✓ Branch 1 taken 1882 times.
5812012624 if (mini_cmb.trigger_global_state)
7651 {
7652 1882 auto rpos_handle = get_rpos_handle_for_screen(screen, lyr, pos);
7653
1/2
✓ Branch 0 taken 1882 times.
✗ Branch 1 not taken.
3764 trig_each_combo_trigger(rpos_handle, [&](combo_trigger const& trig){
7654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1882 times.
1882 return trig.trigger_flags.get(TRIGFLAG_TRIGGLOBALSTATE) && states[trig.trig_gstate];
7655 }, ctrigSWITCHSTATE);
7656 1882 }
7657 5812012624 }
7658
7659
2/2
✓ Branch 0 taken 40395 times.
✓ Branch 1 taken 5814882565 times.
5814922960 if (!mini_cmb.has_global_state)
7660 5814882565 continue;
7661
7662 40395 newcombo const& cmb = combobuf[cid];
7663
2/4
✓ Branch 0 taken 40395 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40395 times.
40395 if(cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK)
7664 {
7665 if(states[cmb.attribytes[0]])
7666 {
7667 set<int32_t> oldData;
7668 //Increment the combo/cset by the attributes
7669 int32_t cmbofs = (cmb.attributes[0]/10000L);
7670 int32_t csofs = (cmb.attributes[1]/10000L);
7671 oldData.insert(scr->data[pos]);
7672 scr->data[pos] = BOUND_COMBO(scr->data[pos] + cmbofs);
7673 scr->cset[pos] = (scr->cset[pos] + csofs) & 15;
7674 if(entry && (cmb.usrflags&cflag8))
7675 {
7676 newcombo const* tmp = &combobuf[scr->data[pos]];
7677 while(tmp->can_cycle())
7678 {
7679 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7680 auto cid = cycle_under ? scr->undercombo : tmp->nextcombo;
7681 if(oldData.find(cid) != oldData.end())
7682 break;
7683 scr->data[pos] = cid;
7684 if(!(tmp->animflags & AF_CYCLENOCSET))
7685 scr->cset[pos] = cycle_under ? scr->undercset : tmp->nextcset;
7686 oldData.insert(cid);
7687 tmp = &combobuf[cid];
7688 }
7689 }
7690 int32_t cmbid = scr->data[pos];
7691 if(combobuf[cmbid].animflags & AF_CYCLE)
7692 {
7693 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7694 combobuf[cmbid].cur_frame=0;
7695 combobuf[cmbid].aclk = 0;
7696 combo_caches::drawing.refresh(cmbid);
7697 }
7698 togglegrid[pos] |= (1<<lyr); //Mark this pos toggled for this layer
7699 if(cmb.type == cCSWITCH) continue; //Switches don't toggle other layers
7700 for(int32_t lyr2 = 0; lyr2 <= 6; ++lyr2) //Toggle same pos on other layers, if flag set
7701 {
7702 if(lyr==lyr2) continue;
7703 if(!(cmb.usrflags&(1<<lyr2))) continue;
7704 if(togglegrid[pos]&(1<<lyr2)) continue;
7705 mapscr* scr_2 = lyr2 == 0 ? base_scr : get_scr_layer_valid(screen, lyr2);
7706 if(!scr_2 || !scr_2->data[pos]) //Don't increment empty space
7707 continue;
7708 newcombo const& cmb_2 = combobuf[scr_2->data[pos]];
7709 if(lyr2 > lyr && (cmb_2.type == cCSWITCH || cmb_2.type == cCSWITCHBLOCK)
7710 && (cmb_2.usrflags & cflag11) && (states[cmb_2.attribytes[0]]))
7711 continue; //This is a switch/block that will be hit later in the loop!
7712 set<int32_t> oldData2;
7713 //Increment the combo/cset by the original cmb's attributes
7714 oldData2.insert(scr_2->data[pos]);
7715 scr_2->data[pos] = BOUND_COMBO(scr_2->data[pos] + cmbofs);
7716 scr_2->cset[pos] = (scr_2->cset[pos] + csofs) & 15;
7717 if(entry && (cmb.usrflags&cflag8)) //Skip cycling on screen entry
7718 {
7719 newcombo const* tmp = &combobuf[scr_2->data[pos]];
7720 while(tmp->can_cycle())
7721 {
7722 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7723 auto cid = cycle_under ? scr_2->undercombo : tmp->nextcombo;
7724 if(oldData2.find(cid) != oldData2.end())
7725 break;
7726 scr_2->data[pos] = cid;
7727 if(!(tmp->animflags & AF_CYCLENOCSET))
7728 scr_2->cset[pos] = cycle_under ? scr_2->undercset : tmp->nextcset;
7729 oldData2.insert(cid);
7730 tmp = &combobuf[cid];
7731 }
7732 }
7733 int32_t cmbid2 = scr_2->data[pos];
7734 if(combobuf[cmbid2].animflags & AF_CYCLE)
7735 {
7736 combobuf[cmbid2].tile = combobuf[cmbid2].o_tile;
7737 combobuf[cmbid2].cur_frame=0;
7738 combobuf[cmbid2].aclk = 0;
7739 combo_caches::drawing.refresh(cmbid2);
7740 }
7741 togglegrid[pos] |= (1<<lyr2); //Mark this pos toggled for this layer
7742 }
7743 }
7744 }
7745 40395 }
7746 33039335 }
7747
7748
4/4
✓ Branch 0 taken 549907 times.
✓ Branch 1 taken 14671243 times.
✓ Branch 2 taken 545163 times.
✓ Branch 3 taken 4744 times.
15221150 if(get_qr(qr_SWITCHES_AFFECT_MOVINGBLOCKS) && mblock2.clk)
7749 {
7750 4744 newcombo const& cmb = combobuf[mblock2.bcombo];
7751
2/4
✓ Branch 0 taken 4744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4744 times.
✗ Branch 3 not taken.
4744 if((cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && (cmb.usrflags & cflag11))
7752 {
7753 if(states[cmb.attribytes[0]])
7754 {
7755 //Increment the combo/cset by the attributes
7756 int32_t cmbofs = (cmb.attributes[0]/10000L);
7757 int32_t csofs = (cmb.attributes[1]/10000L);
7758 mblock2.bcombo = BOUND_COMBO(mblock2.bcombo + cmbofs);
7759 mblock2.cs = (mblock2.cs + csofs) & 15;
7760 int32_t cmbid = mblock2.bcombo;
7761 if(combobuf[cmbid].animflags & AF_CYCLE)
7762 {
7763 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7764 combobuf[cmbid].cur_frame=0;
7765 combobuf[cmbid].aclk = 0;
7766 combo_caches::drawing.refresh(cmbid);
7767 }
7768 }
7769 }
7770 4744 }
7771
7772
2/2
✓ Branch 0 taken 16159 times.
✓ Branch 1 taken 15204991 times.
15221150 if(is_active_screen)
7773 {
7774 15204991 int screen_index_offset = get_region_screen_offset(screen);
7775 15204991 word c = base_scr->numFFC();
7776
2/2
✓ Branch 0 taken 454565983 times.
✓ Branch 1 taken 15204991 times.
469770974 for (int q = 0; q < c; ++q)
7777 {
7778 454565983 auto ffc_handle = *base_scr->getFFCHandle(q, screen_index_offset);
7779
1/2
✓ Branch 0 taken 454565983 times.
✗ Branch 1 not taken.
454794771 trig_each_combo_trigger(ffc_handle, [&](combo_trigger const& trig){
7780
1/2
✓ Branch 0 taken 228788 times.
✗ Branch 1 not taken.
228788 return trig.trigger_flags.get(TRIGFLAG_TRIGGLOBALSTATE) && states[trig.trig_gstate];
7781 }, ctrigSWITCHSTATE);
7782 454565983 }
7783 15204991 }
7784 15221150 }
7785 53270 void toggle_gswitches_load(const screen_handles_t& screen_handles)
7786 {
7787 bool states[256];
7788
2/2
✓ Branch 0 taken 13637120 times.
✓ Branch 1 taken 53270 times.
13690390 for(auto q = 0; q < 256; ++q)
7789 {
7790 13637120 states[q] = game->gswitch_timers[q] != 0;
7791 13637120 }
7792 53270 toggle_gswitches(states, true, screen_handles);
7793 53270 }
7794 14778511 void run_gswitch_timers()
7795 {
7796 14778511 bool states[256] = {false};
7797 14778511 auto& m = game->gswitch_timers.mut_inner();
7798
2/2
✓ Branch 0 taken 3779256576 times.
✓ Branch 1 taken 14778511 times.
3794035087 for(auto it = m.begin(); it != m.end();)
7799 {
7800
2/2
✓ Branch 0 taken 3779255976 times.
✓ Branch 1 taken 600 times.
3779256576 if(it->second > 0)
7801
2/2
✓ Branch 0 taken 599 times.
✓ Branch 1 taken 1 times.
600 if(!--it->second)
7802 {
7803 1 states[it->first] = true;
7804 1 it = m.erase(it);
7805 1 continue;
7806 }
7807 3779256575 ++it;
7808 }
7809 29946390 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7810 15167879 toggle_gswitches(states, false, create_screen_handles(scr));
7811 15167879 });
7812 14778511 }
7813 1118 void onload_gswitch_timers() //Reset all timers that were counting down, no trigger necessary
7814 {
7815
2/2
✓ Branch 0 taken 286208 times.
✓ Branch 1 taken 1118 times.
287326 for(auto q = 0; q < 256; ++q)
7816 {
7817
1/2
✓ Branch 0 taken 286208 times.
✗ Branch 1 not taken.
286208 if(game->gswitch_timers[q] > 0)
7818 game->gswitch_timers[q] = 0;
7819 286208 }
7820 1118 }
7821
7822 /**** View Map ****/
7823
7824 int32_t mapres = 0;
7825 int32_t view_map_show_mode = 3;
7826
7827 124544 bool displayOnMap(int32_t x, int32_t y)
7828 {
7829 124544 int32_t s = (y<<4) + x;
7830 124544 int mi = mapind(cur_map, s);
7831
2/2
✓ Branch 0 taken 67891 times.
✓ Branch 1 taken 56653 times.
124544 if (!(game->maps[mi]&mVISITED))
7832 67891 return false;
7833
7834 // Don't display if not part of DMap
7835
4/4
✓ Branch 0 taken 15628 times.
✓ Branch 1 taken 41025 times.
✓ Branch 2 taken 4655 times.
✓ Branch 3 taken 4311 times.
65619 if(((DMaps[cur_dmap].flags&dmfDMAPMAP) &&
7836
1/2
✓ Branch 0 taken 15628 times.
✗ Branch 1 not taken.
15628 (DMaps[cur_dmap].type != dmOVERW) &&
7837
2/2
✓ Branch 0 taken 12495 times.
✓ Branch 1 taken 3133 times.
15628 !(x >= DMaps[cur_dmap].xoff &&
7838
2/2
✓ Branch 0 taken 8966 times.
✓ Branch 1 taken 3529 times.
12495 x < DMaps[cur_dmap].xoff+8 &&
7839 8966 DMaps[cur_dmap].grid[y]&(128>>(x-DMaps[cur_dmap].xoff)))))
7840 10973 return false;
7841 else
7842 45680 return true;
7843 124544 }
7844
7845 973 void ViewMap()
7846 {
7847 973 ViewingMap = true;
7848
7849 973 BITMAP* mappic = NULL;
7850 static double scales[17] =
7851 {
7852 0.03125, 0.04419, 0.0625, 0.08839, 0.125, 0.177, 0.25, 0.3535,
7853 0.50, 0.707, 1.0, 1.414, 2.0, 2.828, 4.0, 5.657, 8.0
7854 };
7855
7856 // Cursor position for hero, in absolute map coordinates.
7857 973 int32_t lx = ((cur_screen & 15) << 8) + HeroX() + 8;
7858 973 int32_t ly = ((cur_screen >> 4) * 176) + HeroY() + 8;
7859
7860 int32_t px;
7861 int32_t py;
7862
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 973 times.
973 if (is_in_scrolling_region())
7863 {
7864 // Center the player on the middle of the map view.
7865 px = (16*256/2 - lx) * 2;
7866 py = (8*176/2 - ly) * 2;
7867 }
7868 else
7869 {
7870 // Center the current screen on the middle of the map view.
7871 973 px = ((8-(cur_screen&15)) << 9) - 256;
7872 973 py = ((4-(cur_screen>>4)) * 352) - 176;
7873 }
7874
7875 973 int32_t sc = 6;
7876
7877 973 bool done=false, redraw=true;
7878
7879 973 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
7880
7881
1/2
✓ Branch 0 taken 973 times.
✗ Branch 1 not taken.
973 if(!mappic)
7882 {
7883 enter_sys_pal();
7884 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
7885 exit_sys_pal();
7886 return;
7887 }
7888
7889 973 clear_to_color(mappic, WHITE);
7890
7891 973 auto prev_viewport = viewport;
7892 973 viewport.x = 0;
7893 973 viewport.y = 0;
7894
7895 // draw the map
7896 973 BITMAP* screen_bmp = create_bitmap_ex(8, 256, 176);
7897 973 combotile_add_x = 256;
7898 973 combotile_add_y = 0;
7899 973 bool classic_draw = get_qr(qr_CLASSIC_DRAWING_ORDER);
7900
2/2
✓ Branch 0 taken 7784 times.
✓ Branch 1 taken 973 times.
8757 for(int32_t y=0; y<8; y++)
7901 {
7902
2/2
✓ Branch 0 taken 7784 times.
✓ Branch 1 taken 124544 times.
132328 for(int32_t x=0; x<16; x++)
7903 {
7904
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 78864 times.
124544 if (!displayOnMap(x, y))
7905 78864 continue;
7906
7907 45680 int screen = map_scr_xy_to_index(x, y);
7908 45680 auto scrs = loadscr2(screen);
7909 45680 mapscr* scr = &scrs[0];
7910
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if (!scr->is_valid())
7911 continue;
7912
7913 screen_handles_t screen_handles;
7914
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 319760 times.
365440 for (int i = 0; i <= 6; i++)
7915
3/4
✓ Branch 0 taken 319760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103061 times.
✓ Branch 3 taken 216699 times.
319760 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
7916
7917 45680 int xx = 0;
7918 45680 int yy = -playing_field_offset;
7919
7920
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 if (!classic_draw)
7921 for (int layer = -7; layer <= -4; ++layer)
7922 do_ffc_layer(screen_bmp, layer, screen_handles[0], xx, yy);
7923
7924
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 if(classic_draw)
7925 {
7926
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 45660 times.
45680 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
7927
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 do_layer(screen_bmp, 0, screen_handles[2], xx, yy);
7928
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, -2, screen_handles[0], xx, yy);
7929 45680 }
7930
7931
2/2
✓ Branch 0 taken 175 times.
✓ Branch 1 taken 45505 times.
45680 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
7932
1/2
✓ Branch 0 taken 175 times.
✗ Branch 1 not taken.
175 do_layer(screen_bmp, 0, screen_handles[3], xx, yy);
7933
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, -3, screen_handles[0], xx, yy);
7934
7935
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45680 times.
45680 if(!classic_draw)
7936 {
7937 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
7938 do_layer(screen_bmp, 0, screen_handles[2], xx, yy);
7939 do_ffc_layer(screen_bmp, -2, screen_handles[0], xx, yy);
7940 do_ffc_layer(screen_bmp, -1, screen_handles[0], xx, yy);
7941 }
7942
7943
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if(lenscheck(scr,0)) putscr(scr, screen_bmp, 0, 0);
7944
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 0, screen_handles[0], xx, yy);
7945
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[1], xx, yy);
7946
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 1, screen_handles[0], xx, yy);
7947
7948
2/2
✓ Branch 0 taken 45660 times.
✓ Branch 1 taken 20 times.
45680 if(!XOR((scr->flags7&fLAYER2BG), DMaps[cur_dmap].flags&dmfLAYER2BG))
7949 {
7950
1/2
✓ Branch 0 taken 45660 times.
✗ Branch 1 not taken.
45660 do_layer(screen_bmp, 0, screen_handles[2], xx, yy);
7951
1/2
✓ Branch 0 taken 45660 times.
✗ Branch 1 not taken.
45660 do_ffc_layer(screen_bmp, 2, screen_handles[0], xx, yy);
7952 45660 }
7953
7954
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 putscrdoors(scr, screen_bmp, xx, yy);
7955
2/2
✓ Branch 0 taken 41678 times.
✓ Branch 1 taken 4002 times.
45680 if (get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
7956 {
7957
1/2
✓ Branch 0 taken 41678 times.
✗ Branch 1 not taken.
41678 do_layer(screen_bmp, -2, screen_handles[0], xx, yy);
7958
2/2
✓ Branch 0 taken 1782 times.
✓ Branch 1 taken 39896 times.
41678 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
7959 {
7960
1/2
✓ Branch 0 taken 1782 times.
✗ Branch 1 not taken.
1782 do_layer(screen_bmp,-2, screen_handles[1], xx, yy);
7961
1/2
✓ Branch 0 taken 1782 times.
✗ Branch 1 not taken.
1782 do_layer(screen_bmp,-2, screen_handles[2], xx, yy);
7962 1782 }
7963 41678 }
7964
7965
2/2
✓ Branch 0 taken 45505 times.
✓ Branch 1 taken 175 times.
45680 if(!XOR((scr->flags7&fLAYER3BG), DMaps[cur_dmap].flags&dmfLAYER3BG))
7966 {
7967
1/2
✓ Branch 0 taken 45505 times.
✗ Branch 1 not taken.
45505 do_layer(screen_bmp, 0, screen_handles[3], xx, yy);
7968
1/2
✓ Branch 0 taken 45505 times.
✗ Branch 1 not taken.
45505 do_ffc_layer(screen_bmp, 3, screen_handles[0], xx, yy);
7969 45505 }
7970
7971
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[4], xx, yy);
7972
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 4, screen_handles[0], xx, yy);
7973
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, -1, screen_handles[0], xx, yy);
7974
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 39896 times.
45680 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
7975 {
7976
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 do_layer(screen_bmp,-1, screen_handles[1], xx, yy);
7977
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 do_layer(screen_bmp,-1, screen_handles[2], xx, yy);
7978 5784 }
7979
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[5], xx, yy);
7980
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 5, screen_handles[0], xx, yy);
7981
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45680 times.
45680 if(replay_version_check(40))
7982 do_ffc_layer(screen_bmp, -1000, screen_handles[0], xx, yy);
7983
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[6], xx, yy);
7984
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 6, screen_handles[0], xx, yy);
7985
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 7, screen_handles[0], xx, yy);
7986
7987
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 stretch_blit(screen_bmp, mappic, 0, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
7988
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
45680 }
7989 7784 }
7990
7991 973 viewport = prev_viewport;
7992 973 combotile_add_x = 0;
7993 973 combotile_add_y = 0;
7994
7995 973 destroy_bitmap(screen_bmp);
7996 973 clear_keybuf();
7997 973 pause_all_sfx();
7998
7999 // view it
8000 973 int32_t delay = 0;
8001
8002 973 do
8003 {
8004
2/2
✓ Branch 0 taken 178717 times.
✓ Branch 1 taken 29891 times.
208608 if (replay_version_check(0, 11))
8005 29891 load_control_state();
8006
8007 208608 int32_t step = int32_t(16.0/scales[sc]);
8008 208608 step = (step>>1) + (step&1);
8009 208608 bool r = cRbtn();
8010
8011
1/2
✓ Branch 0 taken 208608 times.
✗ Branch 1 not taken.
208608 if(cLbtn())
8012 {
8013 step <<= 2;
8014 delay = 0;
8015 }
8016
8017
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208608 times.
208608 if(r)
8018 {
8019 if(rUp())
8020 {
8021 py+=step;
8022 redraw=true;
8023 }
8024
8025 if(rDown())
8026 {
8027 py-=step;
8028 redraw=true;
8029 }
8030
8031 if(rLeft())
8032 {
8033 px+=step;
8034 redraw=true;
8035 }
8036
8037 if(rRight())
8038 {
8039 px-=step;
8040 redraw=true;
8041 }
8042 }
8043 else
8044 {
8045
2/2
✓ Branch 0 taken 193729 times.
✓ Branch 1 taken 14879 times.
208608 if(Up())
8046 {
8047 14879 py+=step;
8048 14879 redraw=true;
8049 14879 }
8050
8051
2/2
✓ Branch 0 taken 193574 times.
✓ Branch 1 taken 15034 times.
208608 if(Down())
8052 {
8053 15034 py-=step;
8054 15034 redraw=true;
8055 15034 }
8056
8057
2/2
✓ Branch 0 taken 182159 times.
✓ Branch 1 taken 26449 times.
208608 if(Left())
8058 {
8059 26449 px+=step;
8060 26449 redraw=true;
8061 26449 }
8062
8063
2/2
✓ Branch 0 taken 182774 times.
✓ Branch 1 taken 25834 times.
208608 if(Right())
8064 {
8065 25834 px-=step;
8066 25834 redraw=true;
8067 25834 }
8068 }
8069
8070
2/2
✓ Branch 0 taken 21164 times.
✓ Branch 1 taken 187444 times.
208608 if(delay)
8071 21164 --delay;
8072 else
8073 {
8074 187444 bool a = cAbtn();
8075 187444 bool b = cBbtn();
8076
8077
3/4
✓ Branch 0 taken 1721 times.
✓ Branch 1 taken 185723 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1721 times.
187444 if(a && !b)
8078 {
8079
1/2
✓ Branch 0 taken 1721 times.
✗ Branch 1 not taken.
1721 sc=zc_min(sc+1,16);
8080 1721 delay=8;
8081 1721 redraw=true;
8082 1721 }
8083
8084
3/4
✓ Branch 0 taken 927 times.
✓ Branch 1 taken 186517 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 927 times.
187444 if(b && !a)
8085 {
8086
2/2
✓ Branch 0 taken 926 times.
✓ Branch 1 taken 1 times.
927 sc=zc_max(sc-1,0);
8087 927 delay=8;
8088 927 redraw=true;
8089 927 }
8090 }
8091
8092
2/2
✓ Branch 0 taken 208597 times.
✓ Branch 1 taken 11 times.
208608 if(rPbtn())
8093 11 --view_map_show_mode;
8094
8095 208608 px = vbound(px,-4096,4096);
8096 208608 py = vbound(py,-1408,1408);
8097
8098 208608 double scale = scales[sc];
8099
8100
2/2
✓ Branch 0 taken 72838 times.
✓ Branch 1 taken 135770 times.
208608 if(!redraw)
8101 {
8102 135770 blit(scrollbuf_old,framebuf,256,0,0,0,256,232);
8103 135770 }
8104 else
8105 {
8106 72838 clear_to_color(framebuf,BLACK);
8107 145676 stretch_blit(mappic,framebuf,0,0,mappic->w,mappic->h,
8108 72838 int32_t(256+(int64_t(px)-mappic->w)*scale)/2,int32_t(224+(int64_t(py)-mappic->h)*scale)/2,
8109 72838 int32_t(mappic->w*scale),int32_t(mappic->h*scale));
8110
8111 72838 blit(framebuf,scrollbuf_old,0,0,256,0,256,232);
8112 72838 redraw=false;
8113 }
8114
8115 208608 int32_t x = int32_t(256+(px-((2048-int64_t(lx))*2))*scale)/2;
8116 208608 int32_t y = int32_t(224+(py-((704-int64_t(ly))*2))*scale)/2;
8117
8118
2/2
✓ Branch 0 taken 7466 times.
✓ Branch 1 taken 201142 times.
208608 if(view_map_show_mode&1)
8119 {
8120 201142 line(framebuf,x-7,y-7,x+7,y+7,(frame&3)+252);
8121 201142 line(framebuf,x+7,y-7,x-7,y+7,(frame&3)+252);
8122 201142 }
8123
8124
3/4
✓ Branch 0 taken 5600 times.
✓ Branch 1 taken 203008 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5600 times.
208608 if(view_map_show_mode&2 || r)
8125 203008 textprintf_ex(framebuf,font,224,216,WHITE,BLACK,"%1.2f",scale);
8126
8127
1/2
✓ Branch 0 taken 208608 times.
✗ Branch 1 not taken.
208608 if(r)
8128 {
8129 textprintf_ex(framebuf,font,0,208,WHITE,BLACK,"m: %d %d",px,py);
8130 textprintf_ex(framebuf,font,0,216,WHITE,BLACK,"x: %d %d",x,y);
8131 }
8132
8133 208608 advanceframe(false, false);
8134
2/2
✓ Branch 0 taken 29891 times.
✓ Branch 1 taken 178717 times.
208608 if (replay_version_check(11))
8135 178717 load_control_state();
8136
8137
2/2
✓ Branch 0 taken 207636 times.
✓ Branch 1 taken 972 times.
208608 if (getInput(btnS, INPUT_PRESS | INPUT_IGNORE_DISABLE))
8138 972 done = true;
8139
8140
2/2
✓ Branch 0 taken 207635 times.
✓ Branch 1 taken 973 times.
417216 }
8141
2/2
✓ Branch 0 taken 972 times.
✓ Branch 1 taken 207636 times.
208608 while(!done && !Quit);
8142
8143 973 ViewingMap = false;
8144 973 destroy_bitmap(mappic);
8145 973 resume_all_sfx();
8146 973 }
8147
8148 1075 int32_t onViewMap()
8149 {
8150
4/6
✓ Branch 0 taken 1075 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1075 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 102 times.
✓ Branch 5 taken 973 times.
1075 if(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)
8151 {
8152 973 clear_to_color(framebuf,BLACK);
8153 973 textout_centre_ex(framebuf,font,"Drawing map...",128,108,WHITE,BLACK);
8154 973 advanceframe(true);
8155 973 ViewMap();
8156 973 }
8157
8158 1075 return D_O_K;
8159 }
8160
8161 35789833 bool isGrassType(int32_t type)
8162 {
8163
2/2
✓ Branch 0 taken 35113421 times.
✓ Branch 1 taken 676412 times.
35789833 switch(type)
8164 {
8165 case cTALLGRASS:
8166 case cTALLGRASSNEXT:
8167 case cTALLGRASSTOUCHY:
8168 676412 return true;
8169 }
8170
8171 35113421 return false;
8172 35789833 }
8173
8174 20914 bool isFlowersType(int32_t type)
8175 {
8176
2/2
✓ Branch 0 taken 16574 times.
✓ Branch 1 taken 4340 times.
20914 switch(type)
8177 {
8178 case cFLOWERS:
8179 case cFLOWERSTOUCHY:
8180 4340 return true;
8181 }
8182
8183 16574 return false;
8184 20914 }
8185
8186 bool isGenericType(int32_t type)
8187 {
8188 switch(type)
8189 {
8190 case cTRIGGERGENERIC:
8191 return true;
8192 }
8193
8194 return false;
8195 }
8196
8197 26056 bool isBushType(int32_t type)
8198 {
8199
2/2
✓ Branch 0 taken 20914 times.
✓ Branch 1 taken 5142 times.
26056 switch(type)
8200 {
8201 case cBUSH:
8202 case cBUSHNEXT:
8203 case cBUSHTOUCHY:
8204 case cBUSHNEXTTOUCHY:
8205
8206 5142 return true;
8207 }
8208
8209 20914 return false;
8210 26056 }
8211
8212 bool isSlashType(int32_t type)
8213 {
8214 switch(type)
8215 {
8216 case cSLASH:
8217 case cSLASHITEM:
8218 case cSLASHTOUCHY:
8219 case cSLASHITEMTOUCHY:
8220 case cSLASHNEXT:
8221 case cSLASHNEXTITEM:
8222 case cSLASHNEXTTOUCHY:
8223 case cSLASHNEXTITEMTOUCHY:
8224 return true;
8225 }
8226
8227 return false;
8228 }
8229
8230 15695 bool isCuttableNextType(int32_t type)
8231 {
8232
2/2
✓ Branch 0 taken 9788 times.
✓ Branch 1 taken 5907 times.
15695 switch(type)
8233 {
8234 case cSLASHNEXT:
8235 case cSLASHNEXTITEM:
8236 case cTALLGRASSNEXT:
8237 case cBUSHNEXT:
8238 case cSLASHNEXTTOUCHY:
8239 case cSLASHNEXTITEMTOUCHY:
8240 case cBUSHNEXTTOUCHY:
8241 5907 return true;
8242 }
8243
8244 9788 return false;
8245 15695 }
8246
8247 17546 bool isTouchyType(int32_t type)
8248 {
8249
2/2
✓ Branch 0 taken 6050 times.
✓ Branch 1 taken 11496 times.
17546 switch(type)
8250 {
8251 case cSLASHTOUCHY:
8252 case cSLASHITEMTOUCHY:
8253 case cBUSHTOUCHY:
8254 case cFLOWERSTOUCHY:
8255 case cTALLGRASSTOUCHY:
8256 case cSLASHNEXTTOUCHY:
8257 case cSLASHNEXTITEMTOUCHY:
8258 case cBUSHNEXTTOUCHY:
8259 11496 return true;
8260 }
8261
8262 6050 return false;
8263 17546 }
8264
8265 29373830 bool isCuttableType(int32_t type)
8266 {
8267
2/2
✓ Branch 0 taken 28924565 times.
✓ Branch 1 taken 449265 times.
29373830 switch(type)
8268 {
8269 case cSLASH:
8270 case cSLASHITEM:
8271 case cBUSH:
8272 case cFLOWERS:
8273 case cTALLGRASS:
8274 case cTALLGRASSNEXT:
8275 case cSLASHNEXT:
8276 case cSLASHNEXTITEM:
8277 case cBUSHNEXT:
8278
8279 case cSLASHTOUCHY:
8280 case cSLASHITEMTOUCHY:
8281 case cBUSHTOUCHY:
8282 case cFLOWERSTOUCHY:
8283 case cTALLGRASSTOUCHY:
8284 case cSLASHNEXTTOUCHY:
8285 case cSLASHNEXTITEMTOUCHY:
8286 case cBUSHNEXTTOUCHY:
8287 449265 return true;
8288 }
8289
8290 28924565 return false;
8291 29373830 }
8292
8293 17322 bool isCuttableItemType(int32_t type)
8294 {
8295
2/2
✓ Branch 0 taken 424 times.
✓ Branch 1 taken 16898 times.
17322 switch(type)
8296 {
8297 case cSLASHITEM:
8298 case cBUSH:
8299 case cFLOWERS:
8300 case cTALLGRASS:
8301 case cTALLGRASSNEXT:
8302 case cSLASHNEXTITEM:
8303 case cBUSHNEXT:
8304
8305 case cSLASHITEMTOUCHY:
8306 case cBUSHTOUCHY:
8307 case cFLOWERSTOUCHY:
8308 case cTALLGRASSTOUCHY:
8309 case cSLASHNEXTITEMTOUCHY:
8310 case cBUSHNEXTTOUCHY:
8311 16898 return true;
8312 }
8313
8314 424 return false;
8315 17322 }
8316
8317 66 bool is_push(mapscr* m, int32_t pos)
8318 {
8319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if(is_push_flag(m->sflag[pos]))
8320 return true;
8321 66 newcombo const& cmb = combobuf[m->data[pos]];
8322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if(is_push_flag(cmb.flag))
8323 return true;
8324
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 52 times.
66 if(cmb.type == cPUSHBLOCK)
8325 14 return true;
8326
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
52 if(cmb.type == cSWITCHHOOK && (cmb.usrflags&cflag7))
8327 return true; //Counts as 'pushblock' flag
8328 52 return false;
8329 66 }
8330
8331 417 static std::map<int, screen_state_t> screen_states;
8332
8333 35857 std::map<int, screen_state_t>& get_screen_states()
8334 {
8335 35857 return screen_states;
8336 }
8337
8338 44198975 screen_state_t& get_screen_state(int screen)
8339 {
8340 44198975 return screen_states[screen];
8341 }
8342
8343 577 void clear_screen_states()
8344 {
8345 577 screen_states.clear();
8346 577 }
8347
8348 1439 void screen_item_set_state(int screen, ScreenItemState state)
8349 {
8350 1439 get_screen_state(screen).item_state = state;
8351 1439 }
8352
8353 37024 void mark_visited(int screen)
8354 {
8355
2/2
✓ Branch 0 taken 475 times.
✓ Branch 1 taken 36549 times.
37024 if (screen < 0x80)
8356 {
8357
2/2
✓ Branch 0 taken 24611 times.
✓ Branch 1 taken 11938 times.
36549 if(DMaps[cur_dmap].flags&dmfVIEWMAP)
8358 11938 game->maps[mapind(cur_map, screen)] |= mVISITED;
8359
8360 36549 markBmap(-1, screen);
8361 36549 }
8362 37024 }
8363